tracking uninitialized static variables

后端 未结 5 496
孤街浪徒
孤街浪徒 2021-01-12 11:40

I need to debug an ugly and huge math C library, probably once produced by f2c. The code is abusing local static variables, and unfortunately somewhere it seems to

5条回答
  •  Happy的楠姐
    2021-01-12 11:54

    My question is that how to uncover these errors ...

    But these aren't errors: the expectation that a static variable is initialized to 0 is perfectly valid, as is assigning some other value to it.

    So asking for a tool that will automatically find non-errors is unlikely to produce a satisfying result.

    From your description, it appears that somefunc() returns correct result first time it is called, and incorrect result on subsequent calls.

    The simplest way to debug such problems is to have two GDB sessions side-by-side: one freshly-loaded (will compute correct answer), and one with "second iteration" (will compute wrong answer). Then step through both sessions "in parallel", and see where their computation or control flow starts to diverge.

    Since you can usually effectively divide the problem in half, it often doesn't take long to find the bug. Bugs that always reproduce are the easiest ones to find. Just do it.

提交回复
热议问题