views:

183

answers:

4
+3  Q: 

gdb without gcc

Is it possible to run GDB with a program assembled with as and linked with ld? With gcc adding the flag -g allows for debugging but I get the error No symbol table is loaded. Use the "file" command when I try to add breakpoints to a loaded program.

Thanks!

EDIT Maybe I should make it clear that I'm learning and programming in assembly. All I really want is a stack trace but being able to use GDB would be great.

Resolution Running as -g does the trick.

Thank you to all that answered!!

+2  A: 

That's not an error preventing debugging, that's an error setting breakpoints in the way you are trying to do it. Since GDB doesn't have any symbol information, you'll have to set the breakpoints some other way.

Teddy
Can you tell me what that other way is?
Tyler
@Tyler: I would if I knew. :)
Teddy
@Teddy: haha thanks
Tyler
+5  A: 

It is possible. However, you need symbols in order to add symbolic breakpoints, and symbols are provided by debugging info; make sure your assembler and linker are providing those. EDIT With GNU as, use as -g. Or just use gcc -g: if you give it a .s file, it will invoke the assembler and linker as appropriate.

GDB understands debugging info in several formats: stabs, COFF, PE, DWARF, SOM. (Some of these are executable formats with debugging sections, others are debug info formats that can be embedded into executables, such as ELF.) gcc -g usually chooses whatever the platform's default is, gcc -ggdb usually chooses the most expressive (depending on your versions, possibly DWARF-3).

If you have debugging info embedded into or linked to by the executable, gdb will try to load it automatically. If you have it elsewhere, you may need to use file to tell gdb where to find it.

You can still debug without symbolic information. For example, you can issue break *0x89abcdef to insert a breakpoint at that address, if there's any code there.

ephemient
+1  A: 

If you don't have a symbol table, then you can't set breakpoints symbolically (by function name, line of code, etc). You could still set a breakpoint for a specific address, if you know the address you are trying to stop at.

gdb>  b 0x12345678

Of course that's only useful if you know that you want to stop at 0x12345678

What does file say about your executable?

Sam Post
`Reading symbols from ~/Programming/ASM/largest_number...(no debugging symbols found)...done.`largest_number was assembled with `as` and linked with `ld`
Tyler
Fair to assume you actually want to use symbolic breakpoints? Check the arguments to ld, probably a way to add in a symbol table. Check man as and man ld?
Sam Post
+3  A: 

you could try running as with the --gdwarf-2 or -g options, and make sure ld is not called with --strip-debug, and that your makefile/install process is not stripping the executable.

ggiroux