首页 > 其他分享 >调试小技巧

调试小技巧

时间:2023-06-09 16:37:24浏览次数:37  
标签:__ objIEDebugWindow 技巧 System Displays Diagnostics Alt 调试


“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan

1. 中断进入调试器
1.1 c++
_asm { int 3 }

一个宏( macro )

#ifdef DEBUG


#define BREAKPOINT __asm int3


#else


#define BREAKPOINT


#endif



1.2 也可使用

_CrtDbgBreak()

,在crtdbg.h中定义



1.3 所有平台(x86、x64均可用)  __debugbreak() ,定义于intrin.h



1.4 csharp
System.Diagnostics.Debugger.Break();

1.5 其他
可用NULL指针、除零操作等。

2. 定义自己的 assert 宏

void __declspec(noreturn) __assertNoReturn(char *, int, char *);



#if defined(_PREFAST_)


// For PREfast runs


//


   #define myAssert(x) __assume(x)



#elif defined(DBG)


//


// For checked builds with a simple assert mechanism


// (where DBG is the checked build symbol)


//


// The following function call will not cause false-positive


// results because __assertNoReturn will not return. More complex


// macros might return. In that case, use __assume.


//


   #define myAssert(x) ((!(x))?__assertNoReturn(__FILE__, __LINE__, #x):1)


#else


// Free build


   #define myAssert(x)   // Nothing


#endif



3. 调试常用快捷键(VS)


F5 开始程序并进行调试


F10 step over, 逐行调试


F11 step into


shift + F11 step out


ctrl + shift + F10 ,set next statement


CTRL +* : SHOW NEWXT STATEMENT


条件断点:一个例子 name.Equals("Name3")


设置条件断点后,断点符号中间会有一个加号


在VS2010中,断点可以导入、输出


使用 Breakpoint Hit Count



4. 得到当前文件名称和当前行


(.net charp)c# 中的 __File__ __line__


string

 currentFile= new  System.Diagnostics.StackTrace( true ).GetFrame(0).GetFileName();


int  currentLine =  new  System.Diagnostics.StackTrace( true ).GetFrame(0).GetFileLineNumber(); 



String MethodName = new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name;



MethodBase.GetCurrentMethod().Name MethodInfo.GetCurrentMethod().Name [Conditional("DEBUG")] void DebugFunc() { }




调试时一些有用的快捷键(VS2010)


Shortcut Keys

Descriptions

Ctrl-Alt-V, A

Displays the Auto window

Ctrl-Alt-B

Displays the Breakpoints dialog

Ctrl-Alt-C

Displays the Call Stack

Ctrl-Shift-F9

Clears all of the breakpoints in the project

Ctrl-F9

Enables or disables the breakpoint on the current line of code

Ctrl-Alt-E

Displays the Exceptions dialog

Ctrl-Alt-I

Displays the Immediate window

Ctrl-Alt-V, L

Displays the Locals window

Ctrl-Alt-Q

Displays the Quick Watch dialog

Ctrl-Shift-F5

Terminates the current debugging session, rebuilds if necessary, and starts a new debugging session.

Ctrl-F10

Starts or resumes execution of your code and then halts execution when it reaches the selected statement.

Ctrl-Shift-F10

Sets the execution point to the line of code you choose

Alt-NUM *

Highlights the next statement

F5

If not currently debugging, this runs the startup project or projects and attaches the debugger.

Ctrl-F5

Runs the code without invoking the debugger

F11

Step Into

Shift-F11

Executes the remaining lines out from procedure

F10

Executes the next line of code but does not step into any function calls

Shift-F5

Available in break and run modes, this terminates the debugging session

Ctrl-Alt-H

Displays the Threads window to view all of the threads for the current process

F9

Sets or removes a breakpoint at the current line

Ctrl-Alt-W, 1

Displays the Watch 1 window to view the values of variables or watch expressions

Ctrl-Alt-P

Displays the Processes dialog, which allows you to attach or detach the debugger to one or more running processes

Ctrl-D,V

IntelliTrace Event


6. 使用OutputDebugString


vc中使用 OutputDebugString


c#可用:


debug中可见


System.Diagnostics.Debug.WriteLine("I am using dot net debugging");


release 和 debug中均可见


System.Diagnostics.Trace.WriteLine("I am using dot net tracing");


对话框
System.Windows.Forms.MessageBox.Show("Exception at File:Line:\n" + ExceptionToStr(e));

将输出重定向到文件:


System.Diagnostics.Trace.Listeners.Clear();


System.Diagnostics.Trace.AutoFlush=true;


System.Diagnostics.Trace.Listeners.Add(new System.Diagnostics.TextWriterTraceListener("app.log"));



//z 2013-04-28 10:23:21 [email protected][T7,L117,R5,V108]


7. vbscript 调试


Dim objIEDebugWindow

Debug "This is a great way to display intermediate results in a separate window."


Sub Debug( myText )
  ' Uncomment the next line to turn off debugging
  ' Exit Sub

  If Not IsObject( objIEDebugWindow ) Then
    Set objIEDebugWindow = CreateObject( "InternetExplorer.Application" )
    objIEDebugWindow.Navigate "about:blank"
    objIEDebugWindow.Visible = True
    objIEDebugWindow.ToolBar = False
    objIEDebugWindow.Width   = 200
    objIEDebugWindow.Height  = 300
    objIEDebugWindow.Left    = 10
    objIEDebugWindow.Top     = 10
    Do While objIEDebugWindow.Busy
      WScript.Sleep 100
    Loop
    objIEDebugWindow.Document.Title = "IE Debug Window"
    objIEDebugWindow.Document.Body.InnerHTML = _
                 "<b>" & Now & "</b></br>"
  End If

  objIEDebugWindow.Document.Body.InnerHTML = _
                   objIEDebugWindow.Document.Body.InnerHTML _
                   & myText & "<br>" & vbCrLf
End Sub



标签:__,objIEDebugWindow,技巧,System,Displays,Diagnostics,Alt,调试
From: https://blog.51cto.com/u_16156420/6449058

相关文章

  • EC20调试过程备份
    1、模块通电 如图,将单片机引脚(VBAT_EN)拉低,即可给EC20供3.8V电源。2、模块开机如图,单片机引脚拉高500ms,即可让模块开机。TCP步骤:1、给模块上电并开机2、AT+CPIN?查看SIM卡的状态3、AT+CREG?检查是否注册到网络4、AT+CGREG?/AT+CEREG?查询GPRS网络注册状态(2G网络)/......
  • 在使用vs2010调试时大量出现iso_whid,HR PROPAGATED 信息
    //z9/5/20112:[email protected]_whid错误在用visualstudio2010调试时会向dbgview输出大量的如下信息:***HRpropagated:-2147024774[8092]*** SourceFile:d:\iso_whid\x86fre\base\isolation\com找了下有以下这些解决方案1.在dbgview中设置过滤器在d......
  • 简报技巧
    简报技巧s=c^3capabilitycommunicationchance不是自我感觉良好,而是别人认为你做多少,会多少訂定目的:听完简报前后,思维有所改变,让谁去做什么事記住Remember了解Understand相信Believe行動action先讲结论,再讲推论让老板帮你做事,让老板知道你有做事定义问题:应当(最佳標竿,......
  • Vue 调试访问本地后端接口配置
    记录一下本地测试前端的时候怎么访问本地后端接口。时间太长容易忘。。。。1、首先要知道前端在访问后端的时候是怎么加上后端接口地址的。如下图,找到封装http请求的文件,src/utils/rerquest.js该图中的baseURL就是访问时我们加上的后端请求地址。baseURL:process.env.VUE_APP......
  • 深入解析React DnD拖拽原理,轻松掌握拖放技巧!
    我们是袋鼠云数栈UED团队,致力于打造优秀的一站式数据中台产品。我们始终保持工匠精神,探索前端道路,为社区积累并传播经验价值。。本文作者:霁明一、背景1、业务背景业务中会有一些需要实现拖拽的场景,尤其是偏视觉方向以及移动端较多。拖拽在一定程度上能让交互更加便捷,能......
  • RK3588-WIF/BT调试之AP6256
    一、简介AP6256是正基科技推出的一款低成本,低功耗的双模模块。是一款SDIO接口单通道802.11ac双频支持BT5.0蓝牙WiFi二合一模块。Model:AP6256:SDIOWIFI+UARTBTChip:BCM43456WiFi: 2.4G&5GBT:5.0WIFIThroughput:up:196Mbits/secdown:187Mbits/sec二、DTS配置2.1配置SDIO/*SDIO......
  • Linux系统中GDB调试详细操作方法
    第一:启动在shell下敲gdb命令即可启动gdb,启动后会显示下述信息,出现gdb提示符。添加编译指令:gcc-ga.c-otest打开指令:gdbtest  或者gdb  然后输入:filetest➜examplegdbGNUgdb(Ubuntu8.1.1-0ubuntu1)8.1.1Copyright(C)2018F......
  • 互联网(IT)大厂面试技巧(面经)
    目录前言面试的正确姿势实战最后的总结前言虽然资历尚浅,但是也面过不少试,有Google、微软等外企大佬,也有BAT等国内巨头,工作的这几年也有幸当过几次面试官,小鹿这里呢就结合自己的亲身经历,聊一聊我对面试的一些小想法(*^▽^*)我们面试是在面什么?technologythinkingcommunication这是小......
  • [转]比较全面的gdb调试命令
     用GDB调试程序GDB是一个强大的命令行调试工具。大家知道命令行的强大就是在于,其可以形成执行序列,形成脚本。UNIX下的软件全是命令行的,这给程序开发提代供了极大的便利,命令行软件的优势在于,它们可以非常容易的集成在一起,使用几个简单的已有工具的命令,就可以做出一个非常强大......
  • [转]好消息,android平台从froyo 2.2开始支持jni单步调试了
    好消息,android平台从froyo2.2开始支持jni单步调试了北京理工大学 20981 陈罡一、写在前面的话(可以理解为废话)前段时间从网上看了google的io大会,亲眼看到了google在it技术发展和创新领域所做的工作(在此也问候一下apple公司的美术家门,你们辛......