简体   繁体   English

调试器能否生成附加进程的源代码的所有已执行行的列表?

[英]Can a debugger produce a list of all executed lines of source code of an attached process?

I'm working for a company, that does not have a habit of adding log entries in their source code. 我在一家公司工作,没有习惯在其源代码中添加日志条目。

Hence, if something goes wrong, the amount of logs, explaining what might have happened, is too small to make any real analysis. 因此,如果出现问题,说明可能发生的情况的日志量太小而无法进行任何实际分析。

Therefore I'm looking for a tool which can do the following: 因此,我正在寻找一种可以执行以下操作的工具:

  • Attach to a running process and link to the symbols file. 附加到正在运行的进程并链接到符号文件。
  • Follow all lines of source code which are executed. 遵循执行的所有源代码行。
  • After a certain key is pressed (like "Ctrl+C"), produce a report which looks as follows: 按下某个键(例如“ Ctrl + C”)后,生成一个如下所示的报告:

[] []

file1.c:010:  function1(1, 2, 5)
file1.c:011:    sum(1,2)
file1.c:020:      return 3;
file1.c:012:    sum(3,5);
file1.c:020:      return 8;
file1.c:012:    return 8;

I can imagine this question sounding very naïve, but if I can have something which just approaches this result, it might be very useful. 我可以想象这个问题听起来很幼稚,但是如果我可以提出一些接近该结果的方法,它可能会非常有用。

Does anybody know if this can be achieved using windbg , cdb , Visual Studio or any other means? 有人知道是否可以使用windbgcdb ,Visual Studio或任何其他方式来实现?

do you have the source code and symbols for your exe if yes windbg can step and print source lines 如果是的话,windbg可以步进并打印源代码行吗,您是否具有exe的源代码和符号?

demo below for a simple recv sample 下面的演示是一个简单的接收示例

start an executable whose pdb with src info is available 启动一个可执行文件,其带有src信息的pdb可用

:\>cdb recv

Microsoft (R) Windows Debugger Version 10.0.16299.15 X86

windbg breaks on system breakpoint windbg在系统断点处中断

ntdll!LdrpDoDebuggerBreak+0x2c:
771a05a6 cc              int     3

enable loading of line information enable stepping in source mode enable printing of src lines 启用行信息的加载启用单步执行源代码模式启用src线的打印

0:000> .lines
Line number information will be loaded
0:000> l+t
Source options are 1:
     1/t - Step/trace by source line
0:000> l+s
Source options are 5:
     1/t - Step/trace by source line
     4/s - List source code at prompt

disallow all other output except src 禁止除src外的所有其他输出

0:000> .prompt_allow -reg -dis -sym -ea
Allow the following information to be displayed at the prompt:
(Other settings can affect whether the information is actually displayed)
   src - Source info for current instruction
Do not allow the following information to be displayed at the prompt:
   sym - Symbol for current instruction
   dis - Disassembly of current instruction
    ea - Effective address for current instruction
   reg - Register state

go to main and step 10 times you will see each step is showing the src 转到主步骤10次,您将看到每个步骤都显示src

read and use controlling the target in windbg help to know about various execution methods like step until return , step until branch etc 阅读并使用在windbg中控制目标的方法来了解各种执行方法,例如单步执行直到返回,单步执行直到分支等

0:000> g recv!main
ModLoad: 69f50000 69f53000   C:\Windows\system32\api-ms-win-core-synch-l1-2-0.DLL
>   13: int __cdecl main() {
0:000> p 10
>   24:     iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
>   25:     if (iResult != NO_ERROR) {
>   30:     ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
>   31:     if (ConnectSocket == INVALID_SOCKET) {
>   38:     clientService.sin_family = AF_INET;
>   39:     clientService.sin_addr.s_addr = inet_addr( "127.0.0.1" );
>   40:     clientService.sin_port = htons( 27015 );
>   42:     iResult = connect( ConnectSocket, (SOCKADDR*) &clientService, sizeof(clientService) );
>   43:     if ( iResult == SOCKET_ERROR) {
>   44:         closesocket (ConnectSocket);
>   45:         printf("Unable to connect to server: %ld\n", WSAGetLastError());

Unable to connect to server: 0
>   66:         WSACleanup();
>   67:         return 1;
>   88: }
*** The C++ standard library and CRT step filter can be enabled to skip this fun
ction. Run .settings set Sources.SkipCrtCode = true">.settings set Sources.SkipC
rtCode = true to enable it. ***

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM