c++ - How to dump program executioncontrol-flow and local variables - Stack Overflow

Let's suppose I have program like this:int test(int n) {n++;std::cout << n << std::en

Let's suppose I have program like this:

int test(int n) {
    n++;
    std::cout << n << std::endl
    n += 15;
    return n + 1;
}

int main(int argc, char** argv) {
    auto result = test(argv[1]);
    std::cout << result << std::endl
}

How can I record its execution, so I can dump something like:

Visited Function: main with arguments (argc: 2, argv ["path", 7])
Visited Function test with arguments (n: 7)
test: N set to 8
test: N set to 23
test: N set to 24
Exit function test
Main: result set to 24

or at least

Visited Function: main with arguments (argc: 2, argv ["path", 7])
Visited Function test with arguments (n: 7)
test: N set to 8

// or maybe without stdlib if possible
test: Visited operator std::cout with 8
test: Visited operator std::cout with std::endl

test: N set to 23
test: N set to 24
Exit function test
Main: result set to 24
Exit function main

It is like if a ran program under debugger and only used "Step Into" until the program ends. And between all those Step Into I'd dump things like current function name and values of locals.

Why I need that?

I have one program in two versions v1 and v1.01

And 1.01 introduced regression, so I want to compare their behaviour on the same input, so I can automatically find the regression.

Some people suggested instrumentation, but I'd rather have something like rr debugger or windows time travel record because it is universal, language agnostic.

But if it is hard to dump such a thing from those tools, then I'll try to go with instrumentation.

C++, MSVC on Windows or Clang on Linux (preferably MSVC on Windows)

I tried using Windows Time Travel, but I don't know how to dump their recording format into something human readable

Let's suppose I have program like this:

int test(int n) {
    n++;
    std::cout << n << std::endl
    n += 15;
    return n + 1;
}

int main(int argc, char** argv) {
    auto result = test(argv[1]);
    std::cout << result << std::endl
}

How can I record its execution, so I can dump something like:

Visited Function: main with arguments (argc: 2, argv ["path", 7])
Visited Function test with arguments (n: 7)
test: N set to 8
test: N set to 23
test: N set to 24
Exit function test
Main: result set to 24

or at least

Visited Function: main with arguments (argc: 2, argv ["path", 7])
Visited Function test with arguments (n: 7)
test: N set to 8

// or maybe without stdlib if possible
test: Visited operator std::cout with 8
test: Visited operator std::cout with std::endl

test: N set to 23
test: N set to 24
Exit function test
Main: result set to 24
Exit function main

It is like if a ran program under debugger and only used "Step Into" until the program ends. And between all those Step Into I'd dump things like current function name and values of locals.

Why I need that?

I have one program in two versions v1 and v1.01

And 1.01 introduced regression, so I want to compare their behaviour on the same input, so I can automatically find the regression.

Some people suggested instrumentation, but I'd rather have something like rr debugger or windows time travel record because it is universal, language agnostic.

But if it is hard to dump such a thing from those tools, then I'll try to go with instrumentation.

C++, MSVC on Windows or Clang on Linux (preferably MSVC on Windows)

I tried using Windows Time Travel, but I don't know how to dump their recording format into something human readable

Share Improve this question asked Feb 23 at 13:19 EUVEUV 52 bronze badges 6
  • 2 What you really need is a version control system (git) and unit tests. Or are you saying you need to dump an executable for which you don't have the source code? – Pepijn Kramer Commented Feb 23 at 13:24
  • 3 test(argv[1]) won't compile. argv[1] is a char*, while test accepts an int. – Igor Tandetnik Commented Feb 23 at 14:02
  • Have you tried stepping though the program in the debugger to see where the two version diverge? – Ted Lyngmo Commented Feb 23 at 14:22
  • You may have some success with AspectC++ to inject behavior (aspects) into the code. Or instrument the code with entry/exit logging. – Eljay Commented Feb 23 at 17:19
  • you really need is a (git) and unit tests The example that I posted here on SO can be 10 times simplified than real world scenario, so people can understand it easier Or are you saying you need to dump an executable for which you don't have the source code? I have source, but there are literally tens of thousands of commits between two versions and I need to find where the behaviour changes (often it is dependent on runtime values) It's giant codebase with hundreds of contributors, and yes, we have tens of thousands tests, but very often changes/regression are in external code (framework) – EUV Commented Feb 23 at 22:09
 |  Show 1 more comment

1 Answer 1

Reset to default 0

I want to compare their behaviour on the same input

For any program that is longer than ~1000 lines, your approach will result in enormous dumps of local variables.

In addition, you will drown in non-essential differences: process ids, timestamps, local ports are all going to be different. Stack addresses may be different. If you don't disable ASLR, heap addresses will be different etc. etc.

I'd rather have something like rr debugger

The rr is exactly what you need: run both versions of the program under rr until the place where you observe divergence, then run back and forth until you find where the regression happens.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745153690a4613987.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信