Skip to content

Conversation

@quinox
Copy link
Contributor

@quinox quinox commented Jan 26, 2025

  • Feel free to close this PR if you're not interested: I made it for fun while playing around with gdb, just to see what's possible.
  • The WIP part: I only hooked it into one of the assert failures, I think you have a few other roads how testcases could fail. I have no desire to polish this further, take it or leave it 😃

This is a separate implementation but the same idea as #135. I initially tried the other approach, ran into issues, pivoted to this solution, and once it was done I realized how I could achieve my original idea.

This implementation is cleaner but also less useful: instead of providing you with coredumps it will only show similar stack info on the terminal. It is more flexible for customization though: right now it only prints the frame name + local variables but you can show whatever you want.


This PR will show you stack information when an assertion failure is triggered. An example output:

INIT: testStringDistances
RUN: testStringDistances
- [trigger_gdb_if_attached]
  - [fmq_assert]
    b = false (bool)
    failmsg = 0x55555594ddf2 "Values aren't the same" (const char *)
    actual = 0x5555559511c8 "distanceBetweenStrings(\"\", \"whoopsie\")" (const char *)
    expected = 0x5555559511b8 "(unsigned int)0" (const char *)
    file = 0x555555950fd8 "/home/quinox/projects/FlashMQ/FlashMQTests/configtests.cpp" (const char *)
    line = 123 (int)
    - [fmq_compare<unsigned int, unsigned int>]
      t1 = @0x7fffffffdd58 (const unsigned int &)
      t2 = @0x7fffffffdd5c (const unsigned int &)
      actual = 0x5555559511c8 "distanceBetweenStrings(\"\", \"whoopsie\")" (const char *)
      expected = 0x5555559511b8 "(unsigned int)0" (const char *)
      file = 0x555555950fd8 "/home/quinox/projects/FlashMQ/FlashMQTests/configtests.cpp" (const char *)
      line = 123 (int)
      - [MainTests::testStringDistances]
        this = 0x7fffffffe120 (MainTests * const)
FAIL: 'Values aren't the same', distanceBetweenStrings("", "whoopsie") != (unsigned int)0
 in /home/quinox/projects/FlashMQ/FlashMQTests/configtests.cpp, line 123
FAIL: testStringDistances

Tests run: 1. Passed: 0. Failed: 1 (of which 0 exceptions). Total assertions: 1.


Failed tests:
 - testStringDistances

TESTS FAILED
[Inferior 1 (process 13425) exited with code 01]
Bummer


Tail of stderr:

@halfgaar
Copy link
Owner

halfgaar commented Jan 26, 2025

Hey, triggering gdb when attached is cool. It's always been annoying when getting an assert fail and even setting a breakpoint an trying again (assuming the case is reproducible), if the variables are temporaries, you don't see them.

I see that there are also some tricks to do the same for exceptions. That may be useful too. In C# that was always easy, but never got around to seeing if I could do that here. The main context where that is useful, is the 'waitForCondition' line in tests, although I can at least also wrap that around a macro that mentions line number and file.

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