munit icon indicating copy to clipboard operation
munit copied to clipboard

Debugging with munit and visual studio code

Open cnesty opened this issue 3 years ago • 6 comments

Hi is there some setting you can use to debug with munit and visual studio code. Even if I compile with the -g flag, I can only step through the munit code and not the library I'm trying to build. How might one go about that? I now have to write a separate driver program in order to debug my code. It seems counter intuitive.

cnesty avatar Jan 30 '23 17:01 cnesty

outsider comment; feel free to ignore Did you try setting the -g flag on both munit and the other library? Also, how is that other library being built?

codylico avatar Jan 31 '23 12:01 codylico

Yes, I did. What I'm trying to debug is the test themselves. Suppose a test fails, and I want to analyse the code from within munit test framework. I can't. The debugger runs through munit source code but doesn't run the functions in the test. So I can step through munit.c but I can't step through the functions in example.c.

In example.c I can only step through this code

`int main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)]) { /* Finally, we'll actually run our test suite! That second argument

  • is the user_data parameter which will be passed either to the
  • test or (if provided) the fixture setup function. / int munit_rtn = munit_suite_main(&test_suite, (void) "µnit", argc, argv); return munit_rtn; }`

I can't step through any of the test functions. such as these. I've created test by following a similar format. `static MunitResult test_compare(const MunitParameter params[], void* data) { /* We'll use these later / const unsigned char val_uchar = 'b'; const short val_short = 1729; double pi = 3.141592654; char stewardesses = "stewardesses"; char* most_fun_word_to_type;

/* These are just to silence compiler warnings about the parameters

  • being unused. */ (void) params; (void) data;

/* Let's start with the basics. */ munit_assert(0 != 1); //munit_assert(gfc_create() != NULL); // this is my function which gets called and passes the test but I can't step through it.

return MUNIT_OK; }`

This is what I need to do in order to debug the functions. Right now I'm using a separate driver program just for that which is labour-intensive and error-prone.

cnesty avatar Feb 01 '23 14:02 cnesty

If you don't mind me asking, what does your driver program look like?

codylico avatar Feb 03 '23 12:02 codylico

I'm an outsider aswell, but you can disable forking in munit by defining MUNIT_NO_FORK. This will allow stepping trough the tests with vscode / gdb.

Hixos avatar Mar 24 '23 08:03 Hixos

Here is what the GDB docs say about the issue:

https://sourceware.org/gdb/onlinedocs/gdb/Forks.html

So yeah, unless you have specific memory safety concerns, just disable forking like @Hixos mentioned or use the work around mentioned above.

BTW, if anyone is confused about how to compile with no forking, just do this in your munit directory:

gcc -c munit.c -g3 -Wall -DMUNIT_NO_FORK

ldelossa avatar May 02 '23 13:05 ldelossa

You can also run your driver program with the CLI option --no-fork and it'll have the same effect. No need to modify your compilation process.

gcc -o ./build/test -g testbench/*.c

./build/test --no-fork

dargueta avatar Mar 23 '24 15:03 dargueta