Debugger showing archive source

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello all,
I created an archive (lib) file using avr-ar utility, by adding two .o files in a folder. The original sources were compiled using Winavr, makefile and PN. I created a project in AVR studio 6 and added this archive to this new project. I compiled the new project in stdio and when I tried to debug (simulate), I was surprised to see the source code of the archive file components. How is this possible and how can I prevent this from showing up? Thanks for your time.

Nayani

Parthasaradhi Nayani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Object file(.o) may have information about the source file path.

Try increasing the Compiler Optimization to -O3 or -Os and set the debug level to "None"
from "Project Properties ->Toolchain-> AVR/GNU C Compiler"

:D

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Alternatively "avr-strip -g" the .o files before using avr-ar. Clearly they contain DWARF2.

BTW note that while YOU can see the source if you give nothing but .o/.a files to someone else they won't be able to see it. The way Darf2 works is that it doesn't actually embed the C source itself. Just filename and line numbers for the .c files on your hard drive. The person you give the .o/.a won't have those files. They will get a prompt if they try to debug saying "tell the debugger where foo.c is located" but that won't help if they don't have a copy of foo.c

(rather famously Atmel made a release of some of the AVR Toolchain files at one stage that had this kind of info in them and there were a flurry of requests on this message board from people trying to find the c:\hudson\.. files that were mentioned in the .o/.a files!)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello mailtosarathy,
Thanks for the reply. After seeing your reply I checked the makefile and the optimization is set to s, however Debug option was set to dwarf-2. I removed this in makefile, cleaned the project, recompiled and created a new archive with two .o files. I copied this file to the other project created with studio and tried again. But still I see the source code in debug!! Any suggestions please? Thank you.

Parthasaradhi Nayani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

But still I see the source code in debug!!

You are going to get it as long as -g is passed when the files are built (whether you pass just -g, -gdwarf-2 or -g1/-g2/-g3). As I say you can either strip out the -g information from files that are already built with "avr-strip -g foo.o" which rewrites foo.o with the info removed. Or you can change the original Makefile to not pass -g in the first place (it's probably listed amongst the CFLAGS).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello clawson,
Thanks for the replies. As suggested by you I did avr-strip -g for both the .o files and recreated the .a file. Now when I debug in stdio, I get a message in the memory window "unavailable..." and after a small delay disassembly listing is being shown. The same does not occur if say sprintf is called. The other developer may like to debug the code and if my routines are executed similar to sprintf it would be great. I await your suggestions. Thanks once again.

Parthasaradhi Nayani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Of course the same happens if you try to step into printf. The same will happen if you try to "avr-objdump - D" either your .a or the one that contains printf. You simply cannot make code that cannot be disassembled.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nope. If I step through sprintf (as a test) the entire function gets executed and next line is highlighted for stepping/debugging. The same is not happening to a call to my function.

Parthasaradhi Nayani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nope you are wrong. I just built this:

#include 
#include 
#include 

char buff[10];

int main(void) {
	sprintf(buff, "%d", 1234);
	while(1) {
	}
}

then single-stepped into the call to sprintf()...

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Source code will only be shown if it is available.

Debug info does not contain sources, it just contains links to the source locations on file.

If you want 0% info in the library, it's easiest to strip it using strip.

However, some users want to see at least symbols if they debug through a library code. If you don't distribute the sources, the debugger cannot shor the source code.

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Somehow the results I am getting are different from what you (clawson) got. Here is my code snippet

 char buf[30];
   
   sprintf (buf,"hello");
   
   Init_System (2);	// This is my function
   
   while (1);

When I start debug in studio and press F11 sprintf gets executed and Init_system highlights. On pressing F11 I see exactly the same screen you posted. How is sprintf getting executed is something I can not understand. As you all say, source will not be included in archive, I will test it on another computer and post my observations. Thank you all.

Parthasaradhi Nayani

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nayani P wrote:
Somehow the results I am getting are different from what you (clawson) got. Here is my code snippet

 char buf[30];
   
   sprintf (buf,"hello");
   
   Init_System (2);	// This is my function
   
   while (1);

GCC optimizes away the sprintf call and substitutes it with code for basically a memmove, and that's why you're not able to step into the call - there is no call to step into :)

Cliff's code has a format specifier, which prevents GCC from doing that optimization.

Regards

Senthil

 

blog | website

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Senthil,
Thanks for the clarifications. That answers why my code just stepped through.

Parthasaradhi Nayani