Debugging methods without debugging tools

I found myself in a difficult situation when I had to debug a Qt application without almost any debugging tool: the application seems to be starting to use more and more CPUs, because it starts the same action again and again; after many hours, the processor is fully saturated.

The application runs on an embedded ARM Linux device, where gdb does not seem to work, it may be difficult to detect problems with the provided toolchain. Strace seems to be reporting timer actions (this is an OpenGL application, so this is expected). ltrace is unavailable, and compiling it has led to a difficult task, possibly useless. I did not write the application, but the source code is available.

Is there anything else I can do to find out that an application is busy when it consumes so many resources? In any case, do I need to trace all the method calls that the application executes? Is there any other method I can use to try to guess the problem or focus my attention?

EDIT: This is one of the problems with gdb: Only backtrace question marks reported by gdb on ARM . Even creating a ten-line application simulating segfault leads to this.

+6
source share
5 answers

Can you enable core dumps on a machine? Then, when it is playing, you can send it SIGABRT and copy the main dump to your development computer and examine it using a cross-debugger with an available source and unbuilt executable.

It's also important to learn a bitter lesson the next time, not to use such a poorly maintained toolchain.

If this is an option, you can try another toolchain with at least gdbserver if you don't support gdb. I was pleased with the CodeSourcery ARM Lite toolchain.

EDIT: gdb for your situation occurs in two ways:

  • cross-gdb that runs on your development host
  • native gdb that works for your purpose

gdbserver allows you to run your cross-gdb on your development node and connect to the target to remotely debug something on it. So a kernel dump or gdbserver are two ways to use cross-gdb to check something on the target, but only gdbserver will not help you.

If your cross-compiler is like arm-none-linux-gnueabi-gcc , see if there is arm-none-linux-gnueabi-gdb on your dev node.

+4
source

You can try placing debug code in your application.

Select a signal, for example SIGINT. Add a signal handler for this signal. This handler prints a stack trace, or at least the value of an instruction pointer. Then launch the application and send SIGINT several times to find out what your application is doing.

+3
source

Try registering the runtime of various functions. First write down the execution time of the most likely candidates, and if you have eliminated them, continue to use other less likely functions in your program.

The easiest way to log a message is to use std :: cout (or printf) and redirect the output to a file so that you can see the log for the last time.

0
source

You can try running the ARM Zoom profiler version - this should tell you where your code spends most of its time - you can download it for free with a 30-day evaluation license.

0
source

Assuming gcc has something like MSVC files and line macros that expand to the current file and current line, you can create your own pseudo-profiling function. Put this in the header:

 void MyPseudoProfileLog(const char* file, int line, int* count); #define MY_PSEUDO_PROFILE_LOG(file, line) { static int count = 0; MyPseudoProfileLog(file, line, &count); } 

This applies to the cpp file (if you put it in the header, you will get several copies of the static variable, one for each cpp file in which you include the header):

 void MyPseudoProfileLog(const char* file, int line, int* count) { static FILE* f = NULL; const int max_count = 1000; if (++(*count) == max_count) { *count = 0; if (!f) f = fopen("/tmp/my_pseudo_profile_log.log"); fprintf(f, "file=\"%s\", line=%d was passed %d times\n", file, line, max_count); fflush(f); } } 

Then you can paste

 MY_PSEUDO_PROFILE_LOG(__FILE__, __LINE__); 

in different places in your code to find out how often they are called. Keep in mind that this is not thread safe, so use only in the main thread.

0
source

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


All Articles