Get the App
SLTechnology News&Howtos  ›  Servers  › 

Using GDB to debug a multithreaded example

Shulou Source: shulou.com Published: 2022-06-02 04:17:41 11月04日 Update

Write a multithreaded program first.

Makefile

Add the-g parameter to generate adjustable information, which can be debugged.

Pthread is not the default library under Linux, that is, when linking, the entry address of the elder function in the phread library cannot be found, so the link will fail. When gcc compiles, the attachment can be solved by adding the-lpthread parameter.

Gdb test enters debugging

Make a breakpoint where you need to debug, and run runs to the breakpoint.

R runs to the breakpoint, and info thread can view the thread being debugged.

Thread apply all bt lets all threads print stack information

Set scheduler-locking off | on | step

When using the step or continue command to debug the currently debugged thread, other threads are also executing at the same time. If we only want the debugged thread to execute and other threads stop waiting, then lock the thread to be debugged and let it run.

Off: no thread is locked, all threads execute.

On: only the currently debugged thread is executed.

Step: prevents other threads from preempting the current thread when it steps into debugging. Other threads are rerunned only when next, continue, util, and finish are used.

Show scheduler-locking:

The purpose of this command is to see the mode of the current locked thread.

Thank you for reading, hope to help you, thank you for your support to this site!

Tags: Thread time run breakpoint information parameter only command link that is entry function tunable at the same time address place stack mode program adjustable Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Redmi Microsoft Xiaomi Shulou Information