Running addr2line on Windows

Yesterday (or maybe the day before), I was browsing through some of the documentation and some where I ran into some documentation saying something along the line, that addr2line is not installed (or run) on windows, and you need to do something like install a version of it under something like WSL or brew or the like:

I was wondering why? I have been using addr2line on windows for a long time, mainly for debugging Teensy 4.x crash..

There is a version installed with the IDE that works fine for me. The only thing that is not there is the simple wrapper executable addr2line. instead you use:arm-none-eabi-addr2line.exe

In particular, this executable is located in the same place as the other gcc commands that you use as part of your build. In my case this is located at:
C:\Users\kurte\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\bin\arm-none-eabi-addr2line.exe

So for example if I have a mucked up version of blink:

/*
  Blink

  Turns an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
  it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
  the correct LED pin independent of which board is used.
  If you want to know what pin the on-board LED is connected to on your Arduino
  model, check the Technical Specs of your board at:
  https://www.arduino.cc/en/Main/Products

  modified 8 May 2014
  by Scott Fitzgerald
  modified 2 Sep 2016
  by Arturo Guadalupi
  modified 8 Sep 2016
  by Colby Newman

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
*/

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  while (!Serial && millis() < 5000) {}
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.println((uint32_t)&loop, HEX);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);  // turn the LED on (HIGH is the voltage level)
  delay(250);                      // wait for a second
  digitalWrite(LED_BUILTIN, LOW);   // turn the LED off by making the voltage LOW
  delay(250);                      // wait for a second
}

Which printed out: 4101
And I run the command from the temp directory that Arduino built into:

C:\Users\kurte\AppData\Local\Temp\arduino\sketches\8FF1FD4F5F89C44F9E04F5882A575D15>C:\Users\kurte\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\bin\arm-none-eabi-addr2line.exe -e Blink.ino.elf 0x4101
C:\Users\kurte\AppData\Local\Temp\.arduinoIDE-unsaved2024724-12732-1uunws5.01ho\Blink/Blink.ino:35

You will see line 35 is correct.

Note: I don't normally do this full long path name. I have cheated and copied the installed addr2line to another directory that I have, that is on my: PATH

C:\Users\kurte\AppData\Local\Temp\arduino\sketches\8FF1FD4F5F89C44F9E04F5882A575D15>where addr2line.exe
C:\Users\kurte\bin\addr2line.exe

Over the last few years I have had to copy it twice as we changed to a newer version of gcc...

Sorry, I know I should probably try to locate again where I read the need to install it... But I am sort of lazy as I am not doing anything with these boards at the current time.

Kurt

1 Like

I am often guilty of the same thing. After spending little bit searching I think I found what you meant.

TLDR It's ease-of-use for the end user

Assuming this was the documentation you were looking for, here's the intro:

The Arduino UNO R4 WiFi uses CmBacktrace to print useful information from the Arm Cortex-M4 processor as serial output when a runtime error occurs. The output includes an addr2line command that can used to produce a stack trace (also stack backtrace, or stack traceback), which can be used to find the source of the error.

Looks like an end user will get a message saying something akin to "Run addr2line <xyz> to get an file/line number", not C:\\...\\addr2line.exe <xyz> (or whatever the MacOS/Linux equivalents would be)

And this blurb I think really hits it on the head:

The addr2line utility is included in the Arduino UNO R4 Boards boards package. However, running it in this way requires modifying the command included in the output. For convenience, you may want to install addr2line on your system.

Generally, people are lazy and instructions like apt install are preferred over "Go to your Windows Search, enter Modify the system environment Variables, Locate addr2line.exe and append its full path to the current one by clicking the small + , then... ... .. .. And make sure to repeat this with every update that modifies that path. On Linux, the steps are instead <XYZ> and on MacOS they're <ABC> " :wink:

Hope this helped :slight_smile:

Mmm ... maybe I'm missing something, but ... both on macOS and Windows I simply made symbolic links so i can just use the "addr2line" command ...

... on Windows:

mklink C:\Windows\System32\addr2line.exe C:\Users\"user_name"\AppData\Local\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\7-2017q4\bin\arm-none-eabi-addr2line.exe ;

replace "user_name" with your windows user name.

On macOS use the ln -s /path/to/original /path/to/link commend from terminal. The original program is located in:

packages/arduino/tools/arm-none-eabi-gcc/7-2017q4/bin/arm-none-eabi-addr2line

Guglielmo

2 Likes

Yes totally agree!

As an alternative to doing a copy of the exe, you can make a link to it instead.

I found the documentation I was referring to.
UNO R4 WiFi Stack Trace Debug Runtime Errors | Arduino Documentation

Which has:

Which is not true!

1 Like

Dear all,

Thank you for your valuable contributions. I've created a request to update the content of both the tutorial and the Help Center article based on your feedback. We hope to have these updates completed as soon as possible.

Thank you again for your input, and have a great day!

Best regards,

Jorge