Kartoch
Kartoch

Reputation: 7779

Debugging unit test in C using check

I'm trying to use check unit testing framework for my C application. But I can't use the debugger (gdb) with it because of two points:

Does anyone has already met this problem and has a solution?

Upvotes: 9

Views: 5558

Answers (4)

mjdsmith
mjdsmith

Reputation: 1051

I read this and he suggests a very simple solution:

gdb > set environment CK_FORK=no

that worked for me. I could then set a breakpoint in functions the test cases call (that is, the functions under test), and it broke at the right place.

Upvotes: 4

Jonathan Leffler
Jonathan Leffler

Reputation: 754700

Look at the no-fork mode:

Check normally forks to create a separate address space. This allows a signal or early exit to be caught and reported, rather than taking down the entire test program, and is normally very useful. However, when you are trying to debug why the segmentation fault or other program error occurred, forking makes it difficult to use debugging tools.

Upvotes: 12

user50049
user50049

Reputation:

Try TAP (Test Anything Protocol) … it's a lot easier to implement, ship and debug. It's also very easy to make it valgrind-aware and tends to play nicer with gdb.

Upvotes: 0

Paul Praet
Paul Praet

Reputation: 1387

Actually, you CAN use fork-mode too.

gdb has two interesting options related to fork behaviour:
- detach-on-fork (set this to false)
- follow-on-fork (either parent or child; I always take child)

This will make gdb follow the child process. When the child process has ended, you have to manually switch back to the parent process by using the inferior command.

Upvotes: 7

Related Questions