Creating debug symbols for gdb manually












1














Intro. For my compilers course I have to translate some language to assembler. Now my code has a segfault, and I have hard time debugging it. Having an ability to watch variables would simplify the process a lot, but the final asm code has only registers and their derivatives.



Question. How can I create debug symbols for gdb manually? I believe I can propagate all necessary information. Will the separate file be created or will it be part of asm? In the former case how to make gdb aware of that file?



A link to some manual is enough. I've searched for one and was only able to find "gcc -g" and some questions about generating symbol files separately.










share|improve this question




















  • 2




    It's normally part of the asm, with special directives to emit a section of debug info. Look at the output of gcc -S on a .c file, with and without -g. e.g. have a look at the stuff after the .section .debug_info,"",@progbits directive in godbolt.org/z/EdeTvA. (gcc compiling for Linux/ELF MIPS). What target are you compiling for, BTW? Different debug formats exist, with DWARF being the current widely-used on on Linux/ELF targets.
    – Peter Cordes
    Nov 10 at 19:34










  • @PeterCordes, thank you. I understand now that it's part of asm. I guess I have to read about .loc and stuff: stackoverflow.com/a/30212164/2956272. My gcc compiler is x86-64 gcc 7.3.
    – dyukha
    Nov 10 at 19:45








  • 2




    Yup. Or maybe just have your compiler emit comments on the asm source lines, like gcc's -fverbose-asm does (try adding it on the Godbolt link above), and assemble it with an assembler that generates debug info for asm source-level debugging. (like as -g). So you give yourself some way to single-step the asm and see some strings from your compiler attached to each instruction, naming the operands. Doesn't help so much for setting watchpoints, but can help follow the how the compiler is implementing the source logic.
    – Peter Cordes
    Nov 10 at 19:49










  • @PeterCordes, Can you please clarify a bit more? I can see lines like this: mov rdx, QWORD PTR [rbp-8] # tmp89, a. Do I understand correctly that compiler now knows that rdx is tmp89 and QWORD PTR [rbp-8] is a just from that? Will gcc -g <my-asm> compilation do it? If yes, this may be exactly what I need.
    – dyukha
    Nov 10 at 20:02








  • 1




    Yes, the comments just repeat the operand list using C variable names, or variations on tmpXX for internal temporaries. And yeah, I think gcc -g foo.s will give you the debug info to help GDB show the right asm source lines.
    – Peter Cordes
    Nov 10 at 20:12
















1














Intro. For my compilers course I have to translate some language to assembler. Now my code has a segfault, and I have hard time debugging it. Having an ability to watch variables would simplify the process a lot, but the final asm code has only registers and their derivatives.



Question. How can I create debug symbols for gdb manually? I believe I can propagate all necessary information. Will the separate file be created or will it be part of asm? In the former case how to make gdb aware of that file?



A link to some manual is enough. I've searched for one and was only able to find "gcc -g" and some questions about generating symbol files separately.










share|improve this question




















  • 2




    It's normally part of the asm, with special directives to emit a section of debug info. Look at the output of gcc -S on a .c file, with and without -g. e.g. have a look at the stuff after the .section .debug_info,"",@progbits directive in godbolt.org/z/EdeTvA. (gcc compiling for Linux/ELF MIPS). What target are you compiling for, BTW? Different debug formats exist, with DWARF being the current widely-used on on Linux/ELF targets.
    – Peter Cordes
    Nov 10 at 19:34










  • @PeterCordes, thank you. I understand now that it's part of asm. I guess I have to read about .loc and stuff: stackoverflow.com/a/30212164/2956272. My gcc compiler is x86-64 gcc 7.3.
    – dyukha
    Nov 10 at 19:45








  • 2




    Yup. Or maybe just have your compiler emit comments on the asm source lines, like gcc's -fverbose-asm does (try adding it on the Godbolt link above), and assemble it with an assembler that generates debug info for asm source-level debugging. (like as -g). So you give yourself some way to single-step the asm and see some strings from your compiler attached to each instruction, naming the operands. Doesn't help so much for setting watchpoints, but can help follow the how the compiler is implementing the source logic.
    – Peter Cordes
    Nov 10 at 19:49










  • @PeterCordes, Can you please clarify a bit more? I can see lines like this: mov rdx, QWORD PTR [rbp-8] # tmp89, a. Do I understand correctly that compiler now knows that rdx is tmp89 and QWORD PTR [rbp-8] is a just from that? Will gcc -g <my-asm> compilation do it? If yes, this may be exactly what I need.
    – dyukha
    Nov 10 at 20:02








  • 1




    Yes, the comments just repeat the operand list using C variable names, or variations on tmpXX for internal temporaries. And yeah, I think gcc -g foo.s will give you the debug info to help GDB show the right asm source lines.
    – Peter Cordes
    Nov 10 at 20:12














1












1








1







Intro. For my compilers course I have to translate some language to assembler. Now my code has a segfault, and I have hard time debugging it. Having an ability to watch variables would simplify the process a lot, but the final asm code has only registers and their derivatives.



Question. How can I create debug symbols for gdb manually? I believe I can propagate all necessary information. Will the separate file be created or will it be part of asm? In the former case how to make gdb aware of that file?



A link to some manual is enough. I've searched for one and was only able to find "gcc -g" and some questions about generating symbol files separately.










share|improve this question















Intro. For my compilers course I have to translate some language to assembler. Now my code has a segfault, and I have hard time debugging it. Having an ability to watch variables would simplify the process a lot, but the final asm code has only registers and their derivatives.



Question. How can I create debug symbols for gdb manually? I believe I can propagate all necessary information. Will the separate file be created or will it be part of asm? In the former case how to make gdb aware of that file?



A link to some manual is enough. I've searched for one and was only able to find "gcc -g" and some questions about generating symbol files separately.







assembly compiler-construction gdb debug-symbols






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 19:31

























asked Nov 10 at 19:29









dyukha

31618




31618








  • 2




    It's normally part of the asm, with special directives to emit a section of debug info. Look at the output of gcc -S on a .c file, with and without -g. e.g. have a look at the stuff after the .section .debug_info,"",@progbits directive in godbolt.org/z/EdeTvA. (gcc compiling for Linux/ELF MIPS). What target are you compiling for, BTW? Different debug formats exist, with DWARF being the current widely-used on on Linux/ELF targets.
    – Peter Cordes
    Nov 10 at 19:34










  • @PeterCordes, thank you. I understand now that it's part of asm. I guess I have to read about .loc and stuff: stackoverflow.com/a/30212164/2956272. My gcc compiler is x86-64 gcc 7.3.
    – dyukha
    Nov 10 at 19:45








  • 2




    Yup. Or maybe just have your compiler emit comments on the asm source lines, like gcc's -fverbose-asm does (try adding it on the Godbolt link above), and assemble it with an assembler that generates debug info for asm source-level debugging. (like as -g). So you give yourself some way to single-step the asm and see some strings from your compiler attached to each instruction, naming the operands. Doesn't help so much for setting watchpoints, but can help follow the how the compiler is implementing the source logic.
    – Peter Cordes
    Nov 10 at 19:49










  • @PeterCordes, Can you please clarify a bit more? I can see lines like this: mov rdx, QWORD PTR [rbp-8] # tmp89, a. Do I understand correctly that compiler now knows that rdx is tmp89 and QWORD PTR [rbp-8] is a just from that? Will gcc -g <my-asm> compilation do it? If yes, this may be exactly what I need.
    – dyukha
    Nov 10 at 20:02








  • 1




    Yes, the comments just repeat the operand list using C variable names, or variations on tmpXX for internal temporaries. And yeah, I think gcc -g foo.s will give you the debug info to help GDB show the right asm source lines.
    – Peter Cordes
    Nov 10 at 20:12














  • 2




    It's normally part of the asm, with special directives to emit a section of debug info. Look at the output of gcc -S on a .c file, with and without -g. e.g. have a look at the stuff after the .section .debug_info,"",@progbits directive in godbolt.org/z/EdeTvA. (gcc compiling for Linux/ELF MIPS). What target are you compiling for, BTW? Different debug formats exist, with DWARF being the current widely-used on on Linux/ELF targets.
    – Peter Cordes
    Nov 10 at 19:34










  • @PeterCordes, thank you. I understand now that it's part of asm. I guess I have to read about .loc and stuff: stackoverflow.com/a/30212164/2956272. My gcc compiler is x86-64 gcc 7.3.
    – dyukha
    Nov 10 at 19:45








  • 2




    Yup. Or maybe just have your compiler emit comments on the asm source lines, like gcc's -fverbose-asm does (try adding it on the Godbolt link above), and assemble it with an assembler that generates debug info for asm source-level debugging. (like as -g). So you give yourself some way to single-step the asm and see some strings from your compiler attached to each instruction, naming the operands. Doesn't help so much for setting watchpoints, but can help follow the how the compiler is implementing the source logic.
    – Peter Cordes
    Nov 10 at 19:49










  • @PeterCordes, Can you please clarify a bit more? I can see lines like this: mov rdx, QWORD PTR [rbp-8] # tmp89, a. Do I understand correctly that compiler now knows that rdx is tmp89 and QWORD PTR [rbp-8] is a just from that? Will gcc -g <my-asm> compilation do it? If yes, this may be exactly what I need.
    – dyukha
    Nov 10 at 20:02








  • 1




    Yes, the comments just repeat the operand list using C variable names, or variations on tmpXX for internal temporaries. And yeah, I think gcc -g foo.s will give you the debug info to help GDB show the right asm source lines.
    – Peter Cordes
    Nov 10 at 20:12








2




2




It's normally part of the asm, with special directives to emit a section of debug info. Look at the output of gcc -S on a .c file, with and without -g. e.g. have a look at the stuff after the .section .debug_info,"",@progbits directive in godbolt.org/z/EdeTvA. (gcc compiling for Linux/ELF MIPS). What target are you compiling for, BTW? Different debug formats exist, with DWARF being the current widely-used on on Linux/ELF targets.
– Peter Cordes
Nov 10 at 19:34




It's normally part of the asm, with special directives to emit a section of debug info. Look at the output of gcc -S on a .c file, with and without -g. e.g. have a look at the stuff after the .section .debug_info,"",@progbits directive in godbolt.org/z/EdeTvA. (gcc compiling for Linux/ELF MIPS). What target are you compiling for, BTW? Different debug formats exist, with DWARF being the current widely-used on on Linux/ELF targets.
– Peter Cordes
Nov 10 at 19:34












@PeterCordes, thank you. I understand now that it's part of asm. I guess I have to read about .loc and stuff: stackoverflow.com/a/30212164/2956272. My gcc compiler is x86-64 gcc 7.3.
– dyukha
Nov 10 at 19:45






@PeterCordes, thank you. I understand now that it's part of asm. I guess I have to read about .loc and stuff: stackoverflow.com/a/30212164/2956272. My gcc compiler is x86-64 gcc 7.3.
– dyukha
Nov 10 at 19:45






2




2




Yup. Or maybe just have your compiler emit comments on the asm source lines, like gcc's -fverbose-asm does (try adding it on the Godbolt link above), and assemble it with an assembler that generates debug info for asm source-level debugging. (like as -g). So you give yourself some way to single-step the asm and see some strings from your compiler attached to each instruction, naming the operands. Doesn't help so much for setting watchpoints, but can help follow the how the compiler is implementing the source logic.
– Peter Cordes
Nov 10 at 19:49




Yup. Or maybe just have your compiler emit comments on the asm source lines, like gcc's -fverbose-asm does (try adding it on the Godbolt link above), and assemble it with an assembler that generates debug info for asm source-level debugging. (like as -g). So you give yourself some way to single-step the asm and see some strings from your compiler attached to each instruction, naming the operands. Doesn't help so much for setting watchpoints, but can help follow the how the compiler is implementing the source logic.
– Peter Cordes
Nov 10 at 19:49












@PeterCordes, Can you please clarify a bit more? I can see lines like this: mov rdx, QWORD PTR [rbp-8] # tmp89, a. Do I understand correctly that compiler now knows that rdx is tmp89 and QWORD PTR [rbp-8] is a just from that? Will gcc -g <my-asm> compilation do it? If yes, this may be exactly what I need.
– dyukha
Nov 10 at 20:02






@PeterCordes, Can you please clarify a bit more? I can see lines like this: mov rdx, QWORD PTR [rbp-8] # tmp89, a. Do I understand correctly that compiler now knows that rdx is tmp89 and QWORD PTR [rbp-8] is a just from that? Will gcc -g <my-asm> compilation do it? If yes, this may be exactly what I need.
– dyukha
Nov 10 at 20:02






1




1




Yes, the comments just repeat the operand list using C variable names, or variations on tmpXX for internal temporaries. And yeah, I think gcc -g foo.s will give you the debug info to help GDB show the right asm source lines.
– Peter Cordes
Nov 10 at 20:12




Yes, the comments just repeat the operand list using C variable names, or variations on tmpXX for internal temporaries. And yeah, I think gcc -g foo.s will give you the debug info to help GDB show the right asm source lines.
– Peter Cordes
Nov 10 at 20:12

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242650%2fcreating-debug-symbols-for-gdb-manually%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53242650%2fcreating-debug-symbols-for-gdb-manually%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()