Skip to content

Fix #15283 (donate-cpu: the assertion failure message is not saved when Cppcheck crashes) - #9086

Open
danmar wants to merge 4 commits into
cppcheck-opensource:mainfrom
cppchecksolutions:donate-cpu-assertion-message
Open

danmar wants to merge 4 commits into
cppcheck-opensource:mainfrom
cppchecksolutions:donate-cpu-assertion-message

Conversation

@danmar

@danmar danmar commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

This PR breaks the server's crash report for every crash that has an assertion message. glibc starts the message with the program's short name, so the line begins with cppcheck: , for example cppcheck: build/symboldatabase.cpp:6760: ...: Assertion ... failed. The PR puts this line into the head results: section, before the received signal line.

On the server, crashReport() (tools/donate-cpu-server.py:222) and the other reports treat any line that starts with cppcheck: as the version line. If OLD_VERSION is not in that line, they stop reading the file (break). The assertion line does not contain OLD_VERSION, so the server stops before the stack trace. The package is still listed as a crash, but its stack trace disappears from the "Stack traces" section. That is less information than before the change.

Either add a prefix to the message when it is written to the results (for example assertion: ...), or change the server's checks to match only the real version line.

No other problems found. The regex and the dedup logic behave as described.

Comments

# Comment By Where Status
1 Assertion line starts with 'cppcheck: ', so the server stops parsing and the crash stack trace is lost AI review tools/donate_cpu_lib.py:574 🆕 New

@danmar, please fix, resolve or reply to the open and new comments: #1.

Testing

  • I did not build the C++ code: the PR changes only Python (tools/donate_cpu_lib.py and its test).

  • PYTHONPATH=tools python3 -m pytest -v test/tools/donate_cpu_lib_test.py: all 3 tests pass, including the new test_get_assertion_failures. Without PYTHONPATH=tools the test cannot import the module.

  • Server parsing test. I wrote a results file in the format that donate-cpu.py produces, with the stack trace in the layout the PR creates. It is shown below, shortened:

    2026-11-28 10:00
    ftp://ftp.de.debian.org/debian/pool/main/f/foo/foo_1.0.orig.tar.gz
    ...
    cppcheck: 2.22.0 head
    head-info: abc
    count: Crash! 0
    ...
    head results:
    Checking /tmp/foo/a.c ...
    cppcheck: build/symboldatabase.cpp:6760: bool Variable::arrayDimensions(const Settings&, bool&): Assertion `dimension_.tok->values().size() == 1' failed.
    
    Program received signal SIGABRT, Aborted.
    0x00007ffff7a9e9fc in __pthread_kill_implementation () from /lib64/libc.so.6
    #0  0x00007ffff7a9e9fc in __pthread_kill_implementation () from /lib64/libc.so.6
    #1  0x00000000006f2414 in Variable::arrayDimensions (this=0x1) at build/symboldatabase.cpp:6760
    

    I loaded tools/donate-cpu-server.py with importlib and called crashReport(dir, {}) twice: once on this file, and once on the same file without the assertion line.

    • With the assertion line: the package is listed as Crash, but the "Stack traces" section is empty.
    • Without the assertion line: the "Stack traces" section shows Packages: foo, #0 __pthread_kill_implementation (...) from /lib64/libc.so.6 and #1 Variable::arrayDimensions(...) at build/symboldatabase.cpp:6760.

    The cause is the check if line.startswith('cppcheck: '): if OLD_VERSION not in line: break at donate-cpu-server.py:222.

  • Regex spot checks: a trailing \r is handled. A source path that contains spaces is not matched, which is a minor issue.


Automated review of 3218a05 by Claude. The pull request was built and tested locally.

Comment thread tools/donate_cpu_lib.py Resolved

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

The earlier problem is fixed. The program name is now stripped from the assertion message, so the server no longer reads that line as the version line, and the stack trace is parsed again.

One new problem: in a -j run, the messages from the first run's stderr are put into the gdb stack trace together with those from the gdb run. gdb re-runs only the first file that crashed. If several files crash with different assertions, every assertion message ends up just before the received signal line of that one file's stack trace. Messages from other crashes then look like they belong to this backtrace. I reproduced this with a fake cppcheck binary. Apart from that, end-to-end tests with a real glibc assert under gdb, with and without stack-trace capture, worked as intended.

Comments

# Comment By Where Status
1 Assertion line starts with 'cppcheck: ', so the server stops parsing and loses the stack trace AI review general ✅ Fixed
2 'cppcheck: ' prefix of the assertion line is read as the version line by the server reports AI review tools/donate_cpu_lib.py:576 ✅ Fixed
3 With -j, assertion messages from other crashed files are put into the gdb stack trace of the first crashed file AI review tools/donate_cpu_lib.py:565 🆕 New

@danmar, please fix, resolve or reply to the open and new comments: #3.

Testing

  • The PR changes only Python, so I did not build the C++ code. pylint is not installed in the container, so I did not run it.
  • PYTHONPATH=tools python3 -m pytest -q test/tools/donate_cpu_lib_test.py: all 3 tests pass.
  • End to end with real gdb. I compiled a fake cppcheck that prints Checking src/a.c ... and then fails a glibc assert, and called lib.scan_package('/work/scratch/fake', '/work/scratch/src', [], capture_callstack=True).
    • The result is Checking src/a.c ..., a blank line, f.c:3: foo: Assertion x == 1' failed., then Program received signal SIGABRTand the backtrace. The program name is stripped and the line sits before the signal line, so the server'scrashReport` parsing is not affected.
    • With capture_callstack=False the message is put at the start of the output. That is also correct.
  • Mis-attribution with -j. I used a fake binary g.c.
    • Without -j1 it emulates a parallel run. It writes two different glibc assertion lines and two Internal error: Child process crashed with signal 6 lines, for src/a.c and src/b.c, to stderr and exits 1.
    • With -j1 it asserts in checkA.
    • Script: lib.__jobs='-j2'; r = lib.scan_package('/work/scratch/fake','/work/scratch/src',[],True); print(r[1])
    • Output:
      Checking src/a.c ...
      
      lib/checkb.cpp:20: void checkB(): Assertion `y' failed.
      lib/checka.cpp:10: void checkA(): Assertion `x == 1' failed.
      g.c:4: checkA: Assertion `x == 1' failed.
      Program received signal SIGABRT, Aborted.
      #0 ...
      
    • The assertion from src/b.c (checkB) is put into the stack trace of src/a.c.
    • The third line differs from the second only because the fake prints a hand-written text in the first run. With the real binary the two messages would be identical and only one would be kept.

Automated review of f6aaa82 by Claude. The pull request was built and tested locally.

Comment thread tools/donate_cpu_lib.py Outdated
cmd += dir_to_scan
_, st_stdout, _, _ = __run_command(cmd)
_, st_stdout, st_stderr, _ = __run_command(cmd)
for msg in get_assertion_failures(st_stderr):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

assertion_failures starts with every assertion message in the stderr of the first run. With -j that run can contain assertions from several child processes that crashed on different files. gdb is re-run only on sig_file (the first file that crashed), but all of these messages are put just before the received signal line of that trace. A message from another crash then looks like it belongs to this backtrace.

I reproduced this with a fake binary. Its -j2 run writes the assertions for checkB (src/b.c) and checkA (src/a.c), and its gdb run asserts in checkA. The result is:

Checking src/a.c ...

lib/checkb.cpp:20: void checkB(): Assertion `y' failed.
lib/checka.cpp:10: void checkA(): Assertion `x == 1' failed.
Program received signal SIGABRT, Aborted.

Suggested fix: when the gdb run gives a stack trace, put only the messages from st_stderr before the signal line. Keep the messages from the first run for the fallback case where there is no gdb trace.

@danmar
danmar force-pushed the donate-cpu-assertion-message branch from df598f3 to 4a34930 Compare November 28, 2026 18:14

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

I found no new problems. Both earlier problems are fixed:

  • The cppcheck: program name is removed from the assertion message, so the server no longer reads that line as the version line.
  • When gdb produces a trace, only the assertion messages from the gdb run go into it. Messages from the first run are used only when there is no gdb trace, so in a -j run messages from other crashed files no longer end up in the trace.

The two new pytest tests cover both paths.

Comments

# Comment By Where Status
1 Assertion line starts with 'cppcheck: ', so the server stops parsing and loses the stack trace AI review general ✅ Fixed
2 'cppcheck: ' prefix of the assertion line is read as the version line by the server reports AI review tools/donate_cpu_lib.py:577 ✅ Fixed
3 With -j, assertion messages from other crashed files are put into the gdb stack trace of the first crashed file AI review tools/donate_cpu_lib.py:565 ✅ Fixed

Testing

  • I did not build the C++ code, because the PR changes only Python (tools/donate_cpu_lib.py and its test).

  • PYTHONPATH=tools python3 -m pytest -q test/tools/donate_cpu_lib_test.py: all 5 tests pass, including the 3 new ones.

  • End to end with real gdb. I used a fake cppcheck written in C:

    • Without -j1 it writes a glibc assertion line and a Child process crashed with signal 6 line to stderr and exits with 1.
    • With -j1 it prints Checking src/a.c ... and then fails a real assert.

    Script: lib.__jobs='-j2'; lib.scan_package('/work/scratch/f','src',[],capture_callstack)

    • capture_callstack=True: the result is Checking src/a.c ..., a blank line, f/c.c:6: main: Assertion argc==0' failed., Program received signal SIGABRT, Aborted.and then the backtrace. Only the assertion from the gdb run is included, without the program name and before the signal line, so the server'scrashReport` parsing is not affected.
    • capture_callstack=False: the result is the assertion message from the first run (without the program name), followed by the internal-error line.
  • I checked how donate-cpu-server.py crashReport parses this: it matches the signal line with line.find(' received signal ') and treats lines that start with cppcheck: as the version line. Neither check is set off by the inserted line.


Automated review of 4a34930 by Claude. The pull request was built and tested locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants