Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging with munit and visual studio code #90

Open
cnesty opened this issue Jan 30, 2023 · 6 comments
Open

Debugging with munit and visual studio code #90

cnesty opened this issue Jan 30, 2023 · 6 comments

Comments

@cnesty
Copy link

cnesty commented Jan 30, 2023

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.

@codylico
Copy link

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?

@cnesty
Copy link
Author

cnesty commented Feb 1, 2023

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.

@codylico
Copy link

codylico commented Feb 3, 2023

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

@Hixos
Copy link

Hixos commented Mar 24, 2023

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.

@ldelossa
Copy link

ldelossa commented May 2, 2023

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

@dargueta
Copy link

dargueta commented Mar 23, 2024

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

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

No branches or pull requests

5 participants