Is there any way to set argv and argc parameters at runtime?

I need to debug my program, the problem is that this program accepts several parameters. How can I debug a program that accepts parameters? Can I somehow change the argc and argv parameters at runtime?

+3
source share
3 answers

The best way is not to change the arguments at run time, but to debug the instance that has the arguments you need.

For Windows, this can be done in Visual Studio as follows:

  • Right-click on a project in Solution Explorer.
  • โ†’ โ†’ .
  • F5, ( , ).

.

+5

, , .

IDE, , (, Visual Studio "/ " ).

, , , . argc/argv , argc/argv , ( , IDE), .

, argv -style, , argc/argv.

, :

int main( int argc, char** argv)
{
    if (debugging) {
        char** dbg_argv;
        int dbg_argc = argcargv( &dbg_argv, "dummyarg0 my debugging command --line");

        parse_options( dbg_argc, dbg_argv);
    }
    else {
        parse_options( argc, argv);
    }

    // etc...
}

, , , .

+2

If you use GDB:

 gdb ./a.exe
 > break main
 > run arg1 arg2 arg3 etc..
+1
source

Source: https://habr.com/ru/post/1778514/


All Articles