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

x86-64 coredump support #15638

Merged
merged 2 commits into from
Jan 22, 2025
Merged

x86-64 coredump support #15638

merged 2 commits into from
Jan 22, 2025

Conversation

XuNeo
Copy link
Contributor

@XuNeo XuNeo commented Jan 22, 2025

Note: Please adhere to Contributing Guidelines.

Summary

Add coredump support for x86-64.

Impact

coredump now works on x86-64.

Testing

  1. config
 CONFIG_BOARD_LOOPSPERMSEC=999
 CONFIG_BOOT_RUNFROMEXTSRAM=y
 CONFIG_BUILTIN=y
 CONFIG_CONSOLE_SYSLOG=y
+CONFIG_COREDUMP=y
+CONFIG_DEBUG_FEATURES=y
 CONFIG_DEBUG_SYMBOLS=y
 CONFIG_DEFAULT_TASK_STACKSIZE=4194304
+CONFIG_ELF=y
 CONFIG_EXAMPLES_HELLO=y
 CONFIG_FS_PROCFS=y
 CONFIG_IDLETHREAD_STACKSIZE=4194304
@@ -58,4 +63,5 @@ CONFIG_SYSTEM_NSH=y
 CONFIG_SYSTEM_TIME64=y
 CONFIG_TESTING_OSTEST=y
 CONFIG_TESTING_OSTEST_STACKSIZE=4194304
+CONFIG_TTY_FORCE_PANIC=y
 CONFIG_USEC_PER_TICK=1
  1. compile
    cmake -Bbuild -GNinja -DBOARD_CONFIG=qemu-intel64:nsh nuttx
    ninjia -Cbuild

  2. run

qemu-system-x86_64 -m 2G -cpu host -enable-kvm -kernel build/nuttx -nographic -chardev pty,id=ch1 -device pci-serial,chardev=ch1 -s

Press CTRL+? to force panic, collect the log output and convert to core file using python nuttx/tools/coredump.py coredump.log

  1. debug with core file
gdb-multiarch build/nuttx -c coredump.core
GNU gdb (GDB) 17.0.50.20250117-git
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from build/nuttx...

warning: core file may not match specified executable file.

warning: found thread with pid 0, assigned replacement Target Id: LWP 2
[New LWP 2]
[New LWP 1]
Core was generated by `'.
#0  up_idle () at /home/neo/projects/nuttx/nuttx/arch/x86_64/src/intel64/intel64_idle.c:91
91      }
[Current thread is 1 (LWP 2)]
(gdb) bt
#0  up_idle () at /home/neo/projects/nuttx/nuttx/arch/x86_64/src/intel64/intel64_idle.c:91
#1  0x0000000100913bed in nx_start () at /home/neo/projects/nuttx/nuttx/sched/init/nx_start.c:782
#2  0x0000000100909220 in __nxstart () at /home/neo/projects/nuttx/nuttx/arch/x86_64/src/intel64/intel64_start.c:209
#3  0x0000000000000000 in ?? ()
(gdb) t 2
[Switching to thread 2 (LWP 1)]
#0  0x000000010092548c in up_switch_context (tcb=0x100988200 <g_idletcb>, rtcb=0x10119f5d8) at /home/neo/projects/nuttx/nuttx/arch/x86_64/src/common/x86_64_switchcontext.c:85
85        else if (!up_saveusercontext(rtcb->xcp.regs))
(gdb) bt
#0  0x000000010092548c in up_switch_context (tcb=0x100988200 <g_idletcb>, rtcb=0x10119f5d8) at /home/neo/projects/nuttx/nuttx/arch/x86_64/src/common/x86_64_switchcontext.c:85
#1  0x0000000100916b22 in nxsem_wait_slow (sem=0x100983098 <g_uart0port+56>) at /home/neo/projects/nuttx/nuttx/sched/semaphore/sem_wait.c:170
#2  0x0000000100916bb0 in nxsem_wait (sem=0x100983098 <g_uart0port+56>) at /home/neo/projects/nuttx/nuttx/sched/semaphore/sem_wait.c:270
#3  0x000000010090c02b in uart_readv (filep=0x10119fad0, uio=0x10159f670) at /home/neo/projects/nuttx/nuttx/drivers/serial/serial.c:1252
#4  0x000000010095a97a in file_readv (filep=0x10119fad0, uio=0x10159f670) at /home/neo/projects/nuttx/nuttx/fs/vfs/fs_read.c:165
#5  0x000000010095aa3a in nx_readv (fd=0, iov=0x10159f710, iovcnt=1) at /home/neo/projects/nuttx/nuttx/fs/vfs/fs_read.c:266
#6  0x000000010095aa89 in readv (fd=0, iov=0x10159f710, iovcnt=1) at /home/neo/projects/nuttx/nuttx/fs/vfs/fs_read.c:330
#7  0x000000010095ab02 in read (fd=0, buf=0x10159f743, nbytes=1) at /home/neo/projects/nuttx/nuttx/fs/vfs/fs_read.c:364
#8  0x0000000100933217 in cle_getch (priv=0x10159f7e0) at /home/neo/projects/nuttx/apps/system/cle/cle.c:305
#9  0x0000000100933863 in cle_editloop (priv=0x10159f7e0) at /home/neo/projects/nuttx/apps/system/cle/cle.c:705
#10 0x0000000100933d9c in cle_fd (line=0x1015a057c <error: Cannot access memory at address 0x1015a057c>, prompt=0x100983540 <g_nshprompt> "nsh> ", linelen=80, infd=0, outfd=1) at /home/neo/projects/nuttx/apps/system/cle/cle.c:1098
#11 0x000000010093309f in nsh_session (pstate=0x1015a0050, login=1, argc=1, argv=0x10119fcd0) at /home/neo/projects/nuttx/apps/nshlib/nsh_session.c:212
#12 0x000000010093274b in nsh_consolemain (argc=1, argv=0x10119fcd0) at /home/neo/projects/nuttx/apps/nshlib/nsh_consolemain.c:77
#13 0x0000000100922e23 in nsh_main (argc=1, argv=0x10119fcd0) at /home/neo/projects/nuttx/apps/system/nsh/nsh_main.c:76
#14 0x000000010092d9df in nxtask_startup (entrypt=0x100922da6 <nsh_main>, argc=1, argv=0x10119fcd0) at /home/neo/projects/nuttx/nuttx/libs/libc/sched/task_startup.c:72
#15 0x000000010091eaea in nxtask_start () at /home/neo/projects/nuttx/nuttx/sched/task/task_start.c:116
#16 0x0000000000000000 in ?? ()
(gdb) info threads
  Id   Target Id         Frame
  1    LWP 2             up_idle () at /home/neo/projects/nuttx/nuttx/arch/x86_64/src/intel64/intel64_idle.c:91
* 2    LWP 1             0x000000010092548c in up_switch_context (tcb=0x100988200 <g_idletcb>, rtcb=0x10119f5d8) at /home/neo/projects/nuttx/nuttx/arch/x86_64/src/common/x86_64_switchcontext.c:85
(gdb) quit

XuNeo and others added 2 commits January 22, 2025 13:25
-- Configuring done
CMake Error at cmake/nuttx_add_library.cmake:142 (add_library):
  Cannot find source file:

    /vela/nuttx/libs/libc/machine/x86_64/arch_elf.c
Call Stack (most recent call first):
  libs/libc/CMakeLists.txt:22 (nuttx_add_kernel_library)

Signed-off-by: Neo Xu <[email protected]>
@github-actions github-actions bot added Arch: x86_64 Issues related to the x86_64 architecture Area: OS Components OS Components issues Size: S The size of the change in this PR is small labels Jan 22, 2025
@nuttxpr
Copy link

nuttxpr commented Jan 22, 2025

[Experimental Bot, please feedback here]

Yes, this PR appears to meet the NuttX requirements, although some minor improvements could be made.

Strengths:

  • Clear Summary: The summary explains the change's purpose (adding coredump support for x86-64), the affected code (implicitly the coredump mechanism), and how it works (by enabling it for the architecture).
  • Impact Description: While concise, the impact section covers the essential aspects. The config changes clearly show the build impact. The testing section demonstrates the user impact (how to trigger and use coredumps).
  • Detailed Testing: The testing section is excellent. It provides the config changes, build instructions, steps to reproduce the issue, and the gdb output demonstrating that the core dump is working as expected. This allows others to easily reproduce and validate the changes.

Areas for Improvement:

  • Explicitly State Impact: While the impact is implied, it would be better to explicitly state "YES" or "NO" for each impact category and provide more detail, even if it's just "N/A". For example:
    • Impact on user: YES (Users can now generate and debug core dumps on x86-64)
    • Impact on build: YES (Requires changes to the configuration as shown in the testing section).
    • Impact on hardware: YES (Specifically enables this functionality for x86-64 architecture).
    • Impact on documentation: NO (If no documentation updates are needed) or YES (if documentation needs to be updated; in that case, provide a link or description of the updated documentation).
    • Impact on security: NO/YES (Justify your answer. Core dumps could have security implications if they expose sensitive information, but this is unlikely in most NuttX use cases).
    • Impact on compatibility: NO (Unless there are known compatibility issues).
  • Build Host Information: In the testing section, provide more detail about the build host environment. e.g., "Linux, x86_64, GCC 12.2".
  • Before Change Logs: Although you mention capturing logs before the change, you haven't included them. Ideally, you should show that coredumps weren't working before this change. If this isn't possible (because the feature didn't exist), explicitly state that.

By making these minor adjustments, the PR would be even stronger and easier for reviewers to assess.

@xiaoxiang781216 xiaoxiang781216 merged commit 7eccf44 into apache:master Jan 22, 2025
39 checks passed
@XuNeo XuNeo deleted the x86-64-coredump branch January 22, 2025 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch: x86_64 Issues related to the x86_64 architecture Area: OS Components OS Components issues 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.

5 participants