Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug option:change -g to -g3, add macro information to elf #13446

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

anjiahao1
Copy link
Contributor

@anjiahao1 anjiahao1 commented Sep 14, 2024

Summary

Debug option:change -g to -g3, add macro information to elf

Impact

all use debug symbol option

Testing

build qemu & sim

The advantage is that there is more macro information when debugging

i test with qemu mps3-an547, my cpu is i7-12700
test step is:

  1. ./tools/configure.sh mps3-an547:nsh
  2. time make -j20
  3. change -g3 to -g, then time make -j20

with g3 make -j20 84.90s user 33.43s system 1144% cpu 10.341 total
with g0 make -j20 67.12s user 30.45s system 1198% cpu 8.142 total
Compile time increased by 2.199s, 20%

with g3 output file size:

 ls -l nuttx*
-rwxrwxr-x 1 ajh ajh 3751616 Sep 19 11:37 nuttx
-rwxrwxr-x 1 ajh ajh  256020 Sep 19 11:37 nuttx.bin
-rw-rw-r-- 1 ajh ajh  720160 Sep 19 11:37 nuttx.hex
-rw-rw-r-- 1 ajh ajh      47 Sep 19 11:37 nuttx.manifest
-rw-rw-r-- 1 ajh ajh 7619946 Sep 19 11:37 nuttx.map

with g0 output file size:

$ ls -l nuttx*
-rwxrwxr-x 1 ajh ajh 2486576 Sep 19 11:38 nuttx
-rwxrwxr-x 1 ajh ajh  256028 Sep 19 11:38 nuttx.bin
-rw-rw-r-- 1 ajh ajh  720176 Sep 19 11:38 nuttx.hex
-rw-rw-r-- 1 ajh ajh      47 Sep 19 11:38 nuttx.manifest
-rw-rw-r-- 1 ajh ajh 1727622 Sep 19 11:38 nuttx.map

elf increase 50% , map file increase 340 %, bin & hex almost unchanged

readelf -S output with g3:

$ readelf -S nuttx
There are 19 section headers, starting at offset 0x393bc8:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00000000 010000 03e656 00  AX  0   0  8
  [ 2] .ARM.exidx        ARM_EXIDX       0003e658 04e658 000008 00  AL  1   0  4
  [ 3] .data             PROGBITS        01000000 050000 0001b4 00  WA  0   0  4
  [ 4] .bss              NOBITS          010001c0 0501c0 00281c 00  WA  0   0 16
  [ 5] .comment          PROGBITS        00000000 0501b4 000045 01  MS  0   0  1
  [ 6] .ARM.attributes   ARM_ATTRIBUTES  00000000 0501f9 000032 00      0   0  1
  [ 7] .debug_abbrev     PROGBITS        00000000 05022b 03adaf 00      0   0  1
  [ 8] .debug_info       PROGBITS        00000000 08afda 148eed 00      0   0  1
  [ 9] .debug_line       PROGBITS        00000000 1d3ec7 0b99f2 00      0   0  1
  [10] .debug_aranges    PROGBITS        00000000 28d8c0 005c10 00      0   0  8
  [11] .debug_rnglists   PROGBITS        00000000 2934d0 003dd9 00      0   0  1
  [12] .debug_macro      PROGBITS        00000000 2972a9 0702e9 00      0   0  1
  [13] .debug_str        PROGBITS        00000000 307592 066f6c 01  MS  0   0  1
  [14] .debug_frame      PROGBITS        00000000 36e500 00b88c 00      0   0  4
  [15] .debug_line_str   PROGBITS        00000000 379d8c 000155 01  MS  0   0  1
  [16] .symtab           SYMTAB          00000000 379ee4 0129d0 10     17 3885  4
  [17] .strtab           STRTAB          00000000 38c8b4 007248 00      0   0  1
  [18] .shstrtab         STRTAB          00000000 393afc 0000ca 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  D (mbind), y (purecode), p (processor specific)

readelf -S output with g0:

readelf -S nuttx
There are 18 section headers, starting at offset 0x25ee60:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .text             PROGBITS        00000000 010000 03e65e 00  AX  0   0  8
  [ 2] .ARM.exidx        ARM_EXIDX       0003e660 04e660 000008 00  AL  1   0  4
  [ 3] .data             PROGBITS        01000000 050000 0001b4 00  WA  0   0  4
  [ 4] .bss              NOBITS          010001c0 0501c0 00281c 00  WA  0   0 16
  [ 5] .comment          PROGBITS        00000000 0501b4 000045 01  MS  0   0  1
  [ 6] .ARM.attributes   ARM_ATTRIBUTES  00000000 0501f9 000032 00      0   0  1
  [ 7] .debug_abbrev     PROGBITS        00000000 05022b 03a995 00      0   0  1
  [ 8] .debug_info       PROGBITS        00000000 08abc0 1486b9 00      0   0  1
  [ 9] .debug_line       PROGBITS        00000000 1d3279 050bbe 00      0   0  1
  [10] .debug_aranges    PROGBITS        00000000 223e38 005c10 00      0   0  8
  [11] .debug_rnglists   PROGBITS        00000000 229a48 003dd9 00      0   0  1
  [12] .debug_str        PROGBITS        00000000 22d821 00bf91 01  MS  0   0  1
  [13] .debug_frame      PROGBITS        00000000 2397b4 00b88c 00      0   0  4
  [14] .debug_line_str   PROGBITS        00000000 245040 000155 01  MS  0   0  1
  [15] .symtab           SYMTAB          00000000 245198 0129c0 10     16 3884  4
  [16] .strtab           STRTAB          00000000 257b58 007248 00      0   0  1
  [17] .shstrtab         STRTAB          00000000 25eda0 0000bd 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  D (mbind), y (purecode), p (processor specific)

Added .debug_macro section in elf file to enhance the debugging ability of macro, without affecting other debugging

gdb debug will be better like this:

debug with g3 elf

(gdb) p PIDHASH(8)
$1 = 8
(gdb) p PIDHASH(1)
$2 = 1
(gdb) p PID_MM_MEMPOOL
$3 = -1
(gdb) p CONFIG_ARCH_INTERRUPTSTACK
$4 = 2048
(gdb)

debug with g0 elf:

(gdb) p PIDHASH(8)
No symbol "PIDHASH" in current context.
(gdb) p PID_MM_MEMPOOL
No symbol "PID_MM_MEMPOOL" in current context.
(gdb) p CONFIG_ARCH_INTERRUPTSTACK
No symbol "CONFIG_ARCH_INTERRUPTSTACK" in current context.
(gdb)

Of course, I think the current PC performance is better in most cases. More debug information during debugging can help developers solve problems more quickly.

@lupyuen
Copy link
Member

lupyuen commented Sep 18, 2024

[Experimental Bot, please feedback here]

Here's a breakdown of the PR against the NuttX requirements, along with suggestions for improvement:

Strengths:

  • Clear Goal: The PR aims to enhance debugging by changing the debug flag to -g3 and including macro information in the ELF file. This is a valuable improvement for developers.

Areas for Improvement:

  • Summary - Details:
    • Why is -g3 better? Be specific about the additional debug information it provides that's not available with the previous setting.
    • Which macros? If you're only adding specific macro information, mention those.
  • Impact:
    • Build Impact: While you mention building for qemu & sim, does the build process itself change (e.g., build time, binary size)? This is crucial information.
    • Compatibility: Could this change impact compatibility with existing debugging tools or scripts that rely on the previous debug information format?
  • Testing:
    • Insufficient Logs: "build qemu & sim" isn't descriptive enough. Include:
      • Commands: The exact commands you used to build and run your tests (e.g., make distclean, ./tools/configure.sh ..., make, qemu-system-xxx ...).
      • Output Snippets: Show relevant lines from the build process and debugging session that demonstrate:
        • The -g3 flag being used.
        • Macro information now being present in your debugger.
        • Comparison (ideally side-by-side) of debugging with and without your change, highlighting the improvements.
  • Documentation:
    • Impact on Documentation: Does this change require any updates to NuttX documentation? If so, have you made those updates in the PR or a related PR?

Example Testing Logs:

# Before the change (using -g):
$ make ... # Include your build command
$ gdb build/nuttx # Or your preferred debugger
(gdb) p some_macro  # Show output that lacks macro info

# After the change (using -g3):
$ make ... # Same build command, highlighting any changes
$ gdb build/nuttx 
(gdb) p some_macro # Show output that now includes expanded macro information

Revised Summary Example:

Enhance debugging by switching from the -g to the -g3 compiler flag. This provides more comprehensive debug information, including the expansion of [mention specific macros or categories of macros]. This will improve developer experience by making debugging sessions significantly more informative.

In Conclusion:

The PR has potential but needs more detail and robust testing evidence to meet NuttX's standards. Clearly demonstrate the benefits, address potential impacts, and provide comprehensive testing logs to make a strong case for your changes.

@anjiahao1
Copy link
Contributor Author

[Experimental Bot, please feedback here]

Here's a breakdown of the PR against the NuttX requirements, along with suggestions for improvement:

Strengths:

  • Clear Goal: The PR aims to enhance debugging by changing the debug flag to -g3 and including macro information in the ELF file. This is a valuable improvement for developers.

Areas for Improvement:

  • Summary - Details:

    • Why is -g3 better? Be specific about the additional debug information it provides that's not available with the previous setting.
    • Which macros? If you're only adding specific macro information, mention those.
  • Impact:

    • Build Impact: While you mention building for qemu & sim, does the build process itself change (e.g., build time, binary size)? This is crucial information.
    • Compatibility: Could this change impact compatibility with existing debugging tools or scripts that rely on the previous debug information format?
  • Testing:

    • Insufficient Logs: "build qemu & sim" isn't descriptive enough. Include:

      • Commands: The exact commands you used to build and run your tests (e.g., make distclean, ./tools/configure.sh ..., make, qemu-system-xxx ...).

      • Output Snippets: Show relevant lines from the build process and debugging session that demonstrate:

        • The -g3 flag being used.
        • Macro information now being present in your debugger.
        • Comparison (ideally side-by-side) of debugging with and without your change, highlighting the improvements.
  • Documentation:

    • Impact on Documentation: Does this change require any updates to NuttX documentation? If so, have you made those updates in the PR or a related PR?

Example Testing Logs:

# Before the change (using -g):
$ make ... # Include your build command
$ gdb build/nuttx # Or your preferred debugger
(gdb) p some_macro  # Show output that lacks macro info

# After the change (using -g3):
$ make ... # Same build command, highlighting any changes
$ gdb build/nuttx 
(gdb) p some_macro # Show output that now includes expanded macro information

Revised Summary Example:

Enhance debugging by switching from the -g to the -g3 compiler flag. This provides more comprehensive debug information, including the expansion of [mention specific macros or categories of macros]. This will improve developer experience by making debugging sessions significantly more informative.

In Conclusion:

The PR has potential but needs more detail and robust testing evidence to meet NuttX's standards. Clearly demonstrate the benefits, address potential impacts, and provide comprehensive testing logs to make a strong case for your changes.

OK, I will add some instructions later.

@github-actions github-actions bot added the Size: S The size of the change in this PR is small label Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Size: S The size of the change in this PR is small
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants