关于 C 语言中内联汇编 _asm int 3 编译失败的问题?

playerbbs163 2012-10-11 05:08:43
学习驱动开发, 需要在DEBUG版本的驱动中做一个手工的中断, 便于用WINDBG调试.
结果在以下代码中加了一个 _asm int 3 语句 (size_t i 位于 _asm int 3 之后), WDK 始终编译报错,
error C2143: syntax error : missing ';' before 'type'
error C2065: 'i' : undeclaredidentifier

多次尝试之后, 将局部变量的定义语句, 移到了汇编语句之前, 结果就编译成功了.

WHY?? 这个太奇怪了, 不知道哪位大侠能指点一下??


NTSTATUS DriverEntry(PDRIVER_OBJECT driver, PUNICODE_STRING reg_path)
{
//编译成功
size_t i; //局部变量定义必须放在 _asm int 3 之前

#if DBG
_asm int 3
#endif

//编译报错
size_t i; //局部变量定义必须放在 _asm int 3 之前


// 所有的分发函数都设置成一样的。
for(i=0;i<IRP_MJ_MAXIMUM_FUNCTION;i++)
{
driver->MajorFunction[i] = ccpDispatch;
}

// 支持动态卸载。
driver->DriverUnload = ccpUnload;

// 绑定所有的串口。
ccpAttachAllComs(driver);

// 直接返回成功即可。
return STATUS_SUCCESS;
}
...全文
635 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2013-02-21
  • 打赏
  • 举报
回复
__asm int 3 DebugBreak The DebugBreak function causes a breakpoint exception to occur in the current process so that the calling thread can signal the debugger and force it to take some action. If the process is not being debugged, the search logic of a standard exception handler is used. In most cases, this causes the calling process to terminate because of an unhandled breakpoint exception. VOID DebugBreak(VOID) Parameters This function has no parameters. Return Values This function does not return a value. Microsoft Specific Causes a breakpoint in your code, where the user will be prompted to run the debugger. void __debugbreak(); Requirements Intrinsic Architecture __debugbreak x86, IPF, x64 Header file <intrin.h> Remarks The __debugbreak compiler intrinsic, similar to DebugBreak, is a portable Win32 way to cause a breakpoint. Note: When compiling with /clr, a function containing __debugbreak will be compiled to MSIL. asm int 3 causes a function to be compiled to native. For more information, see __asm.
  • 打赏
  • 举报
回复
直接用api吧
void WINAPI DebugBreak(void);
mxliang83 2013-02-20
  • 打赏
  • 举报
回复
我也发现同样的问题了。
AnYidan 2013-02-20
  • 打赏
  • 举报
回复
c89 必须在函数开始声明变量

70,021

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧