Repository navigation
m3gdb: build and work on current Linux (glibc 2.36, gcc 12) - #1250
Conversation
glibc no longer defines paddr_t, and its <proc_service.h> now declares ps_get_thread_area and the ps_p*read/write functions with psaddr_t arguments. Define paddr_t as psaddr_t when <proc_service.h> is used, include gregset.h on that path too (gdb_gregset_t was undeclared), and fix the ps_get_thread_area signatures in gdb and gdbserver. Tested on AMD64_LINUX (Debian 12, gcc 12, glibc 2.36). The i386 changes mirror the amd64 ones but are untested. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
glibc 2.36 libc.so.6, libm.so.6 and ld-linux-x86-64.so.2 contain a SHT_RELR section, which this BFD rejected, so gdb reported them as "not in executable format" and had no symbols for them. Treat SHT_RELR as an ordinary section. Also stop printing "invalid relocation type 37" (R_X86_64_IRELATIVE) and similar for relocation types 27..43, which postdate this BFD and only matter to the linker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The C parts of libm3core and libm3 are compiled with the C compiler's default debug format, DWARF 5 with gcc >= 11. A single such unit made dwarf2_build_psymtabs error out for the whole objfile, so the Modula-3 stabs in the same library were never read: RT0.Typecell could not be found and objects could not be printed. Skip compilation units whose version the reader does not handle (anything but 2 or 4), with one warning per objfile, and read the rest. Skipping per unit rather than per objfile matters for statically linked programs, where the runtime's DWARF 5 units sit in the same executable as the program's own (e.g. C backend, DWARF 2) debug info. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Current glibc's libthread_db returns TD_NOCAPAB for per-thread event enabling. This was a hard error, raised while handling the first thread-creation event, leaving the inferior stopped at __nptl_create_event. The process-wide event mask is sufficient, so ignore TD_NOCAPAB and only warn for other errors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two bugs in the Modula-3 part of decode_line_1: - parse_expression and evaluate_expression were called through catch_errors, whose int result was cast back to a pointer. On LP64 hosts this truncates pointers above 4GB; with a PIE gdb (gcc's default) "break Main__Proc" crashed. Use TRY_CATCH wrappers that return the pointer. - find_m3_function_start_sal discarded the result of SKIP_PROLOGUE and, unlike find_function_start_sal, did not advance to the next line when left in mid-line. With current gcc the breakpoint then sat before the arguments were stored, and the arguments showed garbage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
struct block's language_specific was a union of cplus_specific.namespace and m3_specific.body_block. m3-lang.c sets body_block on Modula-3 blocks, which C/C++ lookups (block_scope, used whenever the current language is C or C++, e.g. in code from the C backend) then read as a struct block_namespace_info *, crashing gdb. Make it a struct so the fields don't overlap, declare m3_specific unconditionally so all translation units agree on the layout, and initialize it in allocate_block. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
print_frame_args used the current language, so a backtrace that mixes C/C++ frames (e.g. from the C backend) with Modula-3 frames (the runtime) printed some arguments with the wrong language, e.g. "Invalid C/C++ type code 29 in symbol table". Temporarily switch to the function's language while printing its arguments, as later gdb versions do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Describe the -no-pie requirement, what to expect with the GCC and C
backends, and how to get DWARF 2 from the C compiler for the C
backend. Fix the language name ("set language Modula-3"; "m3" is
not accepted).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
m3_ascertain_compiler_kind reported what it detected with error(), which throws: the command that first triggered detection was aborted, and in the "Can't detect compiler kind" case the result was assigned after the error() and so never cached. Detection then re-ran and threw on every call, which made e.g. backtraces stop silently after the first frame in programs without Modula-3 markers (plain C, or a statically linked C-backend program). Print the messages instead and cache the result before returning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DW_CFA_remember_state saved only the register rules, not the CFA rule (which DWARF 3 includes in the saved state). gcc and glibc use remember_state / epilogue / restore_state in most functions with an early return; after restore_state the CFA kept the epilogue's value, so unwinding from such a function failed. In particular there was no backtrace out of abort(), i.e. for any Modula-3 runtime error, nor from threads blocked in glibc. Save and restore the CFA rule too, as later gdb versions do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The set printer iterated TYPE_LENGTH / sizeof (long) words, so a set
smaller than a word (e.g. SET OF a 7-element enumeration, 1 byte)
printed as {}. Round the word count up and extract only the bits
present in a partial last word.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
m3_decode_linespec required the whole rest of the line to consist of identifiers, dots and blanks, so "break Main.P if n = 2" was not recognized as a Modula-3 location; it then fell through to the C++ compound-name code and failed. Pass it only the text up to an "if" or "thread" keyword and leave the rest to the breakpoint command. Likewise, the fallback expression-based path in decode_line_1 parsed and consumed the rest of the line; restrict it to the first token. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Breakpoint conditions were parsed in the current language. Before the program runs that is C, so "break Main.P if n = 2" parsed "n = 2" as a C assignment (failing with "Invalid cast" when evaluated, but in general it could modify the variable). Parse the condition in the source language of the breakpoint location when the language is "auto", as later gdb versions do. Also print expressions in the language they were parsed in, so that "info breakpoints" shows a Modula-3 condition correctly while the current language is C. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pthread runtime uses SIGRTMAX (SIG64 on Linux) to suspend threads for the garbage collector. m3gdb sets "handle SIG64 nostop noprint pass" when libm3core.so is loaded, which never happens when the runtime is linked into the executable (build_standalone), so such programs stopped on every GC. Also set it when the inferior is created and the executable itself contains the pthread runtime. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The "auto" demangling style also tries the g++ 2.x scheme, which misreads Modula-3 names produced by the C backend: Main__Fib parses as "Main(int, bool)", so procedure Fib was shown as Main in backtraces. Nothing has emitted the 2.x scheme since gcc 3.0; default to gnu-v3. "set demangle-style auto" restores the old behaviour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Does i386_Linux really have problem? Or it is timeouts, etc? |
hosking
left a comment
There was a problem hiding this comment.
Thanks, Mika. This is a careful series, and I'm happy for it to go in. I went through every commit. These are the ones I checked most closely:
- Restoring the CFA on
DW_CFA_restore_statematches the DWARF spec (the CFA rule is part of the remembered state), and later gdb versions fixed it the same way. - Changing
block.hfrom a union to a struct is safe: both places that allocate a block initialisebody_block(allocate_blockexplicitly,mdebugreadthroughxzalloc). - Skipping DWARF units by version accepts exactly what
partial_read_comp_unit_headalready does (2 and 4), so nothing that used to be read is skipped. It also handles 64-bit initial lengths. - The
TRY_CATCHwrappers and the bounded M3 linespec fit howbreak_command_1takes theifcondition, and the language switches are restored through cleanups, including on error. - Set printing: besides rounding up, it now steps by the target's word size instead of the host's
sizeof (long).
Two small, optional points:
- Now that the "Detected compiler kind …" messages are printed with
printf_filteredrather than raised witherror(), every session will print one. They might be better underinfo_verbose, or dropped. - The unconditional
typedef psaddr_t paddr_t;ingdb_proc_service.hcould clash with an older libc that still definespaddr_t. It's fine on anything current.
@VictorMiasnikov, about I386_LINUX: those two failures are from the CI run on 13 November, in the CMake bootstrap step. That was a CI toolchain problem, since fixed on master by #1275 and #1283. It has nothing to do with this PR. CI doesn't build m3gdb at all, so the testing described above is the evidence for this change.
Yes: I see |
|
Mika, a question about m3gdb, since you brought it back to life in #1250. We're planning how debugging will work once MSIR becomes the only lowering (it produces C or LLVM IR, so the GCC backend and its stabs eventually go). The plan is to rely on stock lldb and current gdb, reading the DWARF that MSIR already emits: records, arrays, open-array dopes, enumerations and objects with their inherited fields. Modula-3-specific printing (TEXT, open arrays, an object's dynamic type, REFANY) would come from lldb data formatters and gdb Python pretty-printers shipped with cm3. m3gdb itself would stay as it is for GCC-backend builds. What stock debuggers won't have is m3gdb's Modula-3 expression evaluator. Which m3gdb features do you actually rely on? If there's something beyond printing values, such as M3 expressions in conditions or calling procedures from the debugger, we'd like to know before we decide what the scripts need to cover. 🤖 Generated with Claude Code |
|
One refinement to the plan above: rather than writing the Modula-3 printing in Python, we'd write it in Modula-3, in the runtime, in the spirit of Ramsey and Hanson's ldb. The runtime already knows every traced object's type (typecode, typecell, and the full description 🤖 Generated with Claude Code |
m3gdb has bit-rotted on current Linux. It no longer compiles against current glibc, can't open current system libraries, and crashes or gives wrong results in several places. This series gets it building and working again on AMD64_LINUX, for programs from both the GCC backend and the C backend, dynamically or statically linked.
Tested on Debian 12 (gcc 12.2, glibc 2.36) with the d5.11.9 compiler. m3gdb was built both through
cm3inm3-sys/m3gdband with configure/make directly. Every commit builds on its own.Commits
Build and platform
paddr_tis gone and theps_*signatures in<proc_service.h>changed. The i386 changes mirror the amd64 ones but are untested.SHT_RELRsection in glibc ≥ 2.36 libraries ("not in executable format"). Also silences warnings for newer x86-64 relocation types.RT0.Typecellwasn't found and objects couldn't be printed. Versions 2 and 4 are still read, which keeps the DWARF 4 support from 7cb2fa6.__nptl_create_event.abort(), so none for any Modula-3 runtime error, and none from threads blocked in glibc.Crashes and wrong results in the Modula-3 support
Linespecs:
catch_errors()returned pointers through anint, which crashed on LP64. Separately, a discardedSKIP_PROLOGUEresult made arguments show garbage at function breakpoints.struct block: the M3body_blockand the C++ namespace pointer shared a union, so gdb crashed whenever the current language was C or C++.Compiler-kind detection printed its "Detected compiler kind" messages with
error(), which aborted whatever command triggered it. In the "can't detect" case it also aborted every later command (e.g.btafter frame #0).Sets smaller than a word (e.g.
SET OFa 7-element enumeration) printed as{}.Conditional breakpoints on M3 locations:
break Main.P if n = 2failed outright. Conditions were also parsed in the current language: beforerunthat is C, wheren = 2is an assignment. They're now parsed in the location's language, andinfo breakpointsprints them in it.SIG64 in statically linked programs: the runtime's GC-suspend signal stopped the program, because
handle SIG64 nostopwas only set whenlibm3core.sowas loaded.Frame arguments are printed in each frame's own language, so mixed C-backend/runtime backtraces print correctly.
Default demangling style gnu-v3: the "auto" style tried the g++ 2.x scheme, which turned the C backend's
Main__FibintoMain(int, bool).Docs (
src/index.html): the-no-pierequirement, what to expect from the GCC and C backends, condition syntax, and the correctset language Modula-3.Testing
Programs must be linked with
-no-pie(cm3 -DPOSITION_INDEPENDENT_EXECUTABLE=-no-pie); gdb 6.4 predates PIE support.:=assignment, M3 operatorsfinish, conditional breakpoints, nested procedures with up-level variables, hardware watchpointsp0/p1/p2program with a simple m3makefile (240) plusr0(5), built statically with both backends. Each is run under m3gdb: break in the main body,bt,info locals, severalnext/step,finish, then run to the end. Out of 490 runs:Known limitations (not addressed here)
print *selfis wrongn_L_71)==)IN("Not yet implemented").cm3.cfgmakesM3_BACKEND_MODEreadonly, so it currently takes a separate config file. Making the backend and C debug flags settable from the command line would be a possible follow-up.🤖 Generated with Claude Code