针对如何在GCC中编译C程序以在WinDbg中启用debugging?和gcc编译运行c程序这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展c–程序以g编译,但在gcc中以链接器错误退出、D
针对如何在GCC中编译C程序以在WinDbg中启用debugging?和gcc编译运行c程序这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展c – 程序以g编译,但在gcc中以链接器错误退出、Debugging using Windbg : Symbols loading、Debugging with GDB 用GDB调试多线程程序、debugging – ZF2 – 如何启用Twig的Debug / Dump功能等相关知识,希望可以帮助到你。
本文目录一览:- 如何在GCC中编译C程序以在WinDbg中启用debugging?(gcc编译运行c程序)
- c – 程序以g编译,但在gcc中以链接器错误退出
- Debugging using Windbg : Symbols loading
- Debugging with GDB 用GDB调试多线程程序
- debugging – ZF2 – 如何启用Twig的Debug / Dump功能
如何在GCC中编译C程序以在WinDbg中启用debugging?(gcc编译运行c程序)
我通过GCC(v7.1.0)编译这样的代码(下面的命令行)。
int func() { return 0x1234; } int main() { func(); return 0; }
gcc。 001_simpleMain.c -O0 -m64 -g
编译后我运行WinDbg(10.0),打开可执行文件(Ctrl + E),程序正在加载。 断点在启动过程中被触发是可以的。 之后,我想打开源代码(Ctrl + O),并尝试把func方法中的断点。
WinDlg告诉我:
是控制-d标准input的默认停止标志? 在Linux C?
在Windows上执行进程并获得结果
从其他进程读写
模拟和CreateProcess
用C ++读取和解释内存页面文件
***错误:模块加载完成,但符号无法加载为G: Examples Gcc a.exe
为什么它不工作? 我应该改变编译参数吗? 我的cpu是AMD64
numa,mbind,segfault
检测到某个连接的USB设备
远程debugging器:指定的帐户不存在
__udivdi3 undefined – 如何find使用它的代码?
Windows上C / GTK应用程序的简单更新机制
由于您在WinDbg中使用Windows,您需要专有的PDB文件 ,其中包含来自Microsoft的调试器工具的调试信息。
GCC将生成可供gdb调试器(在Linux中熟知)使用的调试信息。
gcc -g:
以操作系统的本机格式(stabs,COFF,XCOFF或DWARF)生成调试信息。 GDB可以使用这个调试信息。
如果你已经使用了MinGW或Cygwin,你可以使用gdb ,因为它在MinGW / Cygwin环境中是可用的。 如果没有,可用的Windows有几个gdb实现。
一旦你根据@Andre Kampling的指示建立了PDB文件,WinDbg可能仍然没有找到它们。
可执行文件有一些指向PDB文件的数据。 由于您是在Linux中构建的,因此这将是您的Windows系统上不可用的Linux路径。
因此,您需要正确设置您的符号路径 ,以便WinDbg知道您的位置。
基本上你需要
0:000> .symfix c:symbols
为微软的符号和
0:000> .sympath+ c:pathtoyoursymbols
然后指示WinDbg再次加载它们
0:000> .reload /f 0:000> ld*
c – 程序以g编译,但在gcc中以链接器错误退出
这个代码编译精细g,但在使用gcc编译时会抛出链接器错误.这些错误的原因是什么?
$g++ traits2.cpp $gcc traits2.cpp /tmp/ccI7CNCY.o: In function `__static_initialization_and_destruction_0(int,int)': traits2.cpp:(.text+0x36): undefined reference to `std::ios_base::Init::Init()' traits2.cpp:(.text+0x3b): undefined reference to `std::ios_base::Init::~Init()' /tmp/ccI7CNCY.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status
traits2.ccp文件包含前面提到的带有emtpy main()函数的solution:
#include <iostream> using namespace std; // A default Traits class has no information template<class T> struct Traits { }; // A convenient way to get the Traits of the type of a given value without // having to explicitly write out the type template<typename T> Traits<T> GetTraits(const T&) { return Traits<T>(); } template <int major,int minor> struct A { void f() { cout << major << endl; } }; // Specialisation of the traits for any A<int,int> template<int N1,int N2> struct Traits<A<N1,N2> > { enum { major = N1,minor = N2 }; }; template <> struct A<4,0> { void f() { cout << "Specialized:" << GetTraits(*this).major << endl; } }; int main(int argc,char * argv[] ) { /* A<4,0> p; A<1,2> p2; p.f(); p2.f(); */ return 1; }
解决方法
Debugging using Windbg : Symbols loading
This post explains how to use program symbol files to debug applications or kernel drivers on Windows operating system. On Windows platform, the program symbols are stored in a separate file. These files are referred as pdb files and has the extension .pdb. When debugging a program in windbg, we need these symbol files otherwise what we see in the stack trace is just numerical addresses instead of function names and variable names. We won’t be able to make out anything from these numerical addresses. The symbols stored in pdb files are function names, local variable names, global variable names etc.
Setting symbol path
To use the symbols for debugging, we need to tell windbg which directories it should look into, to find the symbols. To do this, click on File menu and then Symbol File Path. You can enter the path as shown in the below image.
The symbol path in this example is srv*c:\symbols*http://msdl.microsoft.com/download/symbols.
The first path is a local directory and the second path is the Microsoft’s symbol server path. This path is required to get the symbols for Windows libraries like shell32.dll, gdi32.dll, advapi32.dll, kernel32.dll, ntdll.dll and many more libraries. The application we need to debug might be using these libraries.
We can specify the symbol search path in windbg prompt also. The command for this is.sympath
For example to set the above search path we need to run the below command.
.sympath srv*c:\symbols*http://msdl.microsoft.com/download/symbols
To print the current symbol search path just run .sympath command.
.sympath
Loading symbols after setting the path
After setting the symbol search path we need to load the symbols for all the loaded modules in memory. For this run the below command.
.reload /f
To load symbols for a particular binary we can specify the binary file name in the .reload command. For example to load symbols for myapplication.exe you can run the below command.
.reload /f myapplication.exe
In this command you need to provide the full name of the binary name along with the extension. Otherwise you might see the message like below.
“Myapplication” was not found in the image list.
Debugger will attempt to load “Myapplication” at given base 00000000`00000000.Please provide the full image name, including the extension (i.e. kernel32.dll)
for more reliable results.
Issues with symbols loading
If none of the symbol files match with the binary file then .reload command fails with the below error message.
0:041> .reload /f MyApplication.exe
*** ERROR: Module load completed but symbols could not be loaded for MyApplication.exe
When you get this do the following. Enable verbose mode for symbols loading by running the command!sym noisy. And run the .reload command again. Check for the error messages it prints.
0:041> !sym noisy
noisy mode – symbol prompts on
0:041> .reload /f myapplication.exe
SYMSRV: c:\symbols\myapplication.pdb\38266E74B06B4EF3BCC16713A4A1E5E82\myapplication.pdb not found
SYMSRV: http://msdl.microsoft.com/download/symbols/myapplication.pdb/38266E74B06B4EF3BCC16713A4A1E5E82/myapplication.pdb not found
*** WARNING: Unable to verify checksum for myapplication.exe
*** ERROR: Module load completed but symbols could not be loaded for myapplication.exe
DBGHELP: myapplication – no symbols loaded
As you can see none of the symbol search paths have the Myapplication.pdb file. Before looking at how to fix this issue, let’s understand how windbg interpretes the symbol server path.
Understanding ‘SRV’ in symbol server path
Another thing you can notice in the above error is that, Windbg looks for the symbols files in a sub directory with the name myapplication.pdb/38266E74B06B4EF3BCC16713A4A1E5E82. This is because we used the keyword SRV in the symbol search path which indicates that this path need to be used as a symbol server path. For symbol servers, to identify the files path easily, Windbg uses the formatbinaryname.pdb/GUID. Each binary is given a unique GUID when the application is built and this GUID can be printed by the command!lmi binaryname. For example, to print GUID information for MyApplication.exe I need to run the command!lmi myapplication.
Now back to the symbol loading issue for Myapplication.exe. As the existing paths does not have this file, we need to add the path where the file is present. Let’s say the file is located at C:\localsymbls. Then we can add this path to the symbols search using.sympath+command. In our example, we need to run.symapth+ C:\localsymbols. This is a normal directory which directly stores pdb files, it’s not a server path. So we don’t prefix the path with SRV.
0:041> .sympath+ c:\localsymbols
DBGHELP: Symbol Search Path: srv*c:\symbols*http://msdl.microsoft.com/download/symbols;c:\localsymbols
DBGHELP: Symbol Search Path: srv*c:\symbols*http://msdl.microsoft.com/download/symbols;c:\localsymbols
Symbol search path is: srv*c:\symbols*http://msdl.microsoft.com/download/symbols;c:\localsymbols
Expanded Symbol search path is: srv*c:\symbols*http://msdl.microsoft.com/download/symbols;c:\localsymbols
0:041> .reload /f myapplication.exe
SYMSRV: c:\symbols\myapplication.pdb\38266E74B06B4EF3BCC16713A4A1E5E82\myapplication.pdb not found
SYMSRV: http://msdl.microsoft.com/download/symbols/myapplication.pdb/38266E74B06B4EF3BCC16713A4A1E5E82/myapplication.pdb not found
DBGHELP: c:\localsymbols\myapplication.pdb – mismatched pdb
DBGHELP: c:\localsymbols\exe\myapplication.pdb – file not found
DBGHELP: c:\localsymbols\symbols\exe\myapplication.pdb – file not foundDBGHELP: Couldn’t load mismatched pdb for myapplication.exe
*** ERROR: Module load completed but symbols could not be loaded for myapplication.exeDBGHELP: myapplication – no symbols loaded
Now we are into another problem. Windbg detected the symbol file but it says that the symbol file is not matching with the exe file. Let’s see how to fix this in the next section.
Symbol file not matching
If you see this issue, you need to crosscheck with your build numbers and pick up the right pdb file. If you are sure that the pdb file you are using is the right one, but still seeing this message, then you can use /i switch to load the symbols even if there is no match.
0:041> .reload /i myapplication.exe
SYMSRV: c:\symbols\myapplication.pdb\38266E74B06B4EF3BCC16713A4A1E5E82\myapplication.pdb not found
SYMSRV: http://msdl.microsoft.com/download/symbols/myapplication.pdb/38266E74B06B4EF3BCC16713A4A1E5E82/myapplication.pdb not found
DBGHELP: c:\localsymbols\myapplication.pdb – mismatched pdb
DBGHELP: c:\localsymbols\exe\myapplication.pdb – file not found
DBGHELP: c:\localsymbols\symbols\exe\myapplication.pdb – file not foundDBGHELP: Loaded mismatched pdb for myapplication.exe
DBGENG: myapplication.exe has mismatched symbols – type “.hh dbgerr003″ for details
DBGHELP: myapplication – private symbols & lines
c:\localsymbols\myapplication.pdb – unmatched
As you can see it looks for a matching pdb in all the search paths. As it does not find any, it loads the mismatched pdb in the end.
I hope this post has helped you in understanding how symbols loading works in Windbg. If something is not clear to you, or if you have any other questions, please share it in the comments below.
Debugging with GDB 用GDB调试多线程程序
Debugging with GDB
http://www.delorie.com/gnu/docs/gdb/gdb_25.html
GDB调试多线程程序总结
一直对GDB多线程调试接触不多,最近因为工作有了一些接触,简单作点记录吧。 先介绍一下GDB多线程调试的基本命令。 info threads 显示当前可调试的所有线程,每个线程会有一个GDB为其分配的ID,后面操作线程的时候会用到这个ID。 前面有*的是当前调试的线程。 thread ID 切换当前调试的线程为指定ID的线程。 break thread_test.c:123 thread all在所有线程中相应的行上设置断点thread apply ID1 ID2 command 让一个或者多个线程执行GDB命令command。thread apply all command 让所有被调试线程执行GDB命令command。 set scheduler-locking off|on|step 估计是实际使用过多线程调试的人都可以发现,在使用step或者continue命令调试当前被调试线程的时候,其他线程也是同时执行的,怎么只让被调试程序执行呢?通过这个命令就可以实现这个需求。off 不锁定任何线程,也就是所有线程都执行,这是默认值。 on 只有当前被调试程序会执行。 step 在单步的时候,除了next过一个函数的情况(熟悉情况的人可能知道,这其实是一个设置断点然后continue的行为)以外,只有当前线程会执行。
gdb对于多线程程序的调试有如下的支持:
- 线程产生通知:在产生新的线程时, gdb会给出提示信息
(gdb) r
Starting program: /root/thread
[New Thread 1073951360 (LWP 12900)]
[New Thread 1082342592 (LWP 12907)]---以下三个为新产生的线程
[New Thread 1090731072 (LWP 12908)]
[New Thread 1099119552 (LWP 12909)]
- 查看线程:使用info threads可以查看运行的线程。
(gdb) info threads
4 Thread 1099119552 (LWP 12940) 0xffffe002 in ?? ()
3 Thread 1090731072 (LWP 12939) 0xffffe002 in ?? ()
2 Thread 1082342592 (LWP 12938) 0xffffe002 in ?? ()
* 1 Thread 1073951360 (LWP 12931) main (argc=1, argv=0xbfffda04) at thread.c:21
(gdb)
注意,行首的蓝色文字为gdb分配的线程号,对线程进行切换时,使用该该号码,而不是上文标出的绿色数字。
另外,行首的红色星号标识了当前活动的线程
- 切换线程:使用 thread THREADNUMBER 进行切换,THREADNUMBER 为上文提到的线程号。下例显示将活动线程从 1 切换至 4。
(gdb) info threads
4 Thread 1099119552 (LWP 12940) 0xffffe002 in ?? ()
3 Thread 1090731072 (LWP 12939) 0xffffe002 in ?? ()
2 Thread 1082342592 (LWP 12938) 0xffffe002 in ?? ()
* 1 Thread 1073951360 (LWP 12931) main (argc=1, argv=0xbfffda04) at thread.c:21
(gdb) thread 4
[Switching to thread 4 (Thread 1099119552 (LWP 12940))]#0 0xffffe002 in ?? ()
(gdb) info threads
* 4 Thread 1099119552 (LWP 12940) 0xffffe002 in ?? ()
3 Thread 1090731072 (LWP 12939) 0xffffe002 in ?? ()
2 Thread 1082342592 (LWP 12938) 0xffffe002 in ?? ()
1 Thread 1073951360 (LWP 12931) main (argc=1, argv=0xbfffda04) at thread.c:21
(gdb)
以上即为使用gdb提供的对多线程进行调试的一些基本命令。另外,gdb也提供对线程的断点设置以及对指定或所有线程发布命令的命令。
初次接触gdb下多线程的调试,往往会忽视gdb中活动线程的概念。一般来讲,在使用gdb调试的时候,只有一个线程为活动线程,如果希望得到其他的线程的输出结果,必须使用thread命令切换至指定的线程,才能对该线程进行调试或观察输出结果。
debugging – ZF2 – 如何启用Twig的Debug / Dump功能
我看过整个谷歌,我找不到任何真正与这个问题有关的东西.虽然ZFC-Twig模块可以在配置中使用它,但它似乎不是.
谢谢
解决方法
在ZfcTwig模块中,只需将此扩展名添加到config(doc):
'zfctwig' => [ 'extensions' => [ 'Twig_Extension_Debug',],
关于如何在GCC中编译C程序以在WinDbg中启用debugging?和gcc编译运行c程序的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于c – 程序以g编译,但在gcc中以链接器错误退出、Debugging using Windbg : Symbols loading、Debugging with GDB 用GDB调试多线程程序、debugging – ZF2 – 如何启用Twig的Debug / Dump功能的相关知识,请在本站寻找。
本文标签: