fdebug 调试器使用

来源:互联网 发布:网络代理设置 编辑:程序博客网 时间:2024/05/16 06:01

reactos 源码带了一个调试工具fdebug, 这个调试器原本是通过串口来连接reactos,但实际上这种方式很麻烦,必须要有两台机器。比较好的方式就是通过虚拟机用pipe方式来调试,但首先就要修改fdebug的源代码,改为通过pipe来连接,打开rs232.c 文件,找到Rs232OpenPortWin32函数:

[cpp] view plaincopy
  1. BOOL Rs232OpenPortWin32(TCHAR* CommPort)  
  2. {  
  3.     TCHAR   PortName[MAX_PATH];  
  4.     DWORD   ErrorCode;  
  5.   
  6.     // First check and make sure they don't already have the  
  7.     // OBD2 connection open. We don't want to open things twice.  
  8.     if (hPortHandle != NULL)  
  9.     {  
  10.         _tprintf(TEXT("Port handle not NULL. Must be already open. Returning FALSE...\n"));  
  11.         return FALSE;  
  12.     }  
  13.   
  14.     _stprintf(PortName, TEXT("\\\\.\\%s"), CommPort);  
  15.   
  16.     hPortHandle = CreateFile(PortName,  
  17.                             GENERIC_READ|GENERIC_WRITE,  
  18.                             0,  
  19.                             0,  
  20.                             OPEN_EXISTING,  
  21.                             0,  
  22.                             0);  
  23.   
  24.     if (hPortHandle == INVALID_HANDLE_VALUE)  
  25.     {  
  26.         hPortHandle = NULL;  
  27.         ErrorCode = GetLastError();  
  28.   
  29.         _tprintf(TEXT("CreateFile(\"%s\") failed. GetLastError() = %lu.\n"), PortName, ErrorCode);  
  30.   
  31.         return FALSE;  
  32.     }  
  33.   
  34.     return TRUE;  
  35. }  

这儿可以把PortName 改为\\\.\\pipe\com1;

然后在fdebug.c 的Rs232Thread函数处:

[cpp] view plaincopy
  1. VOID Rs232Thread(VOID* Parameter)  
  2. {  
  3.     BYTE    Byte;  
  4.     TCHAR   String[MAX_PATH];  
  5.     MSG     msg;  
  6.     DWORD   dwNumberOfBytesWritten;  
  7.   
  8.           UNREFERENCED_PARAMETER(Parameter);  
  9.   
  10.     dwThreadId = GetCurrentThreadId();  
  11.   
  12.     if (!Rs232OpenPortWin32(strComPort))  
  13.     {  
  14.         MessageBox(hMainWnd, TEXT("Error opening port!"), TEXT("Error"), MB_OK|MB_ICONSTOP);  
  15.         bConnected = FALSE;  
  16.         return;  
  17.     }  
  18.   
  19.     //_stprintf(String, TEXT("%s,n,8,1"), strBaudRate); 注释掉这儿  
  20.     //if (!Rs232ConfigurePortWin32(String))  
  21.     //{  
  22.     //  MessageBox(hMainWnd, TEXT("Error configuring port!"), TEXT("Error"), MB_OK|MB_ICONSTOP);  
  23.     //  bConnected = FALSE;  
  24.     //  return;  
  25.     //}                                                注释掉这儿  
  26.   
  27.     while (bConnected)  
  28.     {  
  29.         if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))  
  30.         {  
  31.             if (msg.message == WM_CHAR)  
  32.             {  
  33.                 Rs232WriteByteWin32((BYTE)msg.wParam);  
  34.   
  35.                 if (bLocalEcho && msg.wParam != (WPARAM)TEXT('\r'))  
  36.                 {  
  37.                     PostMessage(hDisplayWnd, WM_CHAR, (WPARAM)msg.wParam, (LPARAM)0);  
  38.   
  39.                     if (hCaptureFile)  
  40.                     {  
  41.                         WriteFile(hCaptureFile, &msg.wParam, sizeof(TCHAR), &dwNumberOfBytesWritten, NULL);  
  42.                     }  
  43.                 }  
  44.             }  
  45.         }  
  46.   
  47.         if (Rs232ReadByteWin32(&Byte))  
  48.         {  
  49.             _stprintf(String, TEXT("%c"), Byte);  
  50.   
  51.             PostMessage(hDisplayWnd, WM_CHAR, (WPARAM)String[0], (LPARAM)0);  
  52.   
  53.             if (hCaptureFile)  
  54.             {  
  55.                 WriteFile(hCaptureFile, &String[0], sizeof(TCHAR), &dwNumberOfBytesWritten, NULL);  
  56.             }  
  57.         }  
  58.     }  
  59.   
  60.     dwThreadId = 0;  
  61.     Rs232ClosePortWin32();  
  62. }  


 

注释掉对 Rs232ConfigurePortWin32() 的调用。因为对pipe来说,是不用配置这样的参数的,然后就可以编译了。

 

默认情况下,fdebug并不会编译的(看来reactos本身是想淘汰掉这种调试工具,因为现在有了其他调试工具ReactosDBG)

打开freeldr目录下的freeldr.rebuild,增加如下的命令:

<directory name="fdebug">
 <xi:include href="fdebug/fdebug.rbuild" />
 </directory>

保存退出,在编译环境下执行:

make  freeldr_fdebug

这样就可以用了

原创粉丝点击