I am debugging using objdump and gdb, but they show different addresses, which makes debugging difficult! Is it possible to get the same addresses somehow?
Asked
Active
Viewed 32 times
0
-
2You have a position independent executable so objdump is showing offsets while gdb is showing virtual addresses. What do you need objdump for anyway? That said, the translation is a simple addition in the top bits (note you did not show the same code in objdump and gdb). Alternatively you can make a legacy (non-PIE) executable in which case you will get virtual addresses from objdump too. – Jester Sep 01 '22 at 11:57
-
Is there a way to let objdump add the base load address and then provide the ouput? Is there a way to get that base load address from gdb somehow? This will make them consistent. – user3488903 Sep 01 '22 at 12:37
-
1Yes, you can calculate the offset from a known symbol, e.g. look at the address of `main`. Then use `objdump --adjust-vma=`. Note that will then break symbols. What do you need objdump for? – Jester Sep 01 '22 at 12:50
-
i need objdump for dumping assembly code of all sections (text, plt, got) along with their addresses. – user3488903 Sep 01 '22 at 12:55
-
@Jester objdump is how compiler explorer (godbolt) gets all its output. You can dump the code with the source interleaved for example. It is very useful if you are trying to check for optimizations in code. – Something Something Sep 01 '22 at 12:55
-
@HenriqueBucher yes but you don't care about addresses then. Also you do not need objdump because the compiler can emit assembly instead. – Jester Sep 01 '22 at 13:03
-
@Jester The compiler can emit assembly but not interleaved. gdb disassembly is a pain in the butt. He might be debugging and looking at the disassembly. I would advise him to run lldb (from llvm) instead. Much better visualization. – Something Something Sep 01 '22 at 13:05
-
You could use `gcc -fno-pie -no-pie` to make a non-relocatable executable, with absolute addresses chosen by the linker and hard-coded in the file (where `objdump` can see them, not just in a running process.) – Peter Cordes Sep 01 '22 at 16:42