简体   繁体   中英

Visual Studio 2012 - break when errno set

I'm getting a domain error somewhere in a couple of hundred lines of code and I'd like to find which line is causing it. My first thought was to set a data breakpoint on _errno() (since the errno macro expands to *_errno() , I reasoned that _errno() should give the address where the errno error code is stored). However, Visual Studio complains that the identifier _errno is undefined.

What is the correct way to break when errno is set in Visual Studio?

It is a function , not a variable. It returns a pointer to an int, you need to know that pointer value to set a data breakpoint.

Best way to go about it is to write this line of code at the start of main():

 errno = 0;

And set a breakpoint on the next line. Switch to the disassembly window, it typically resembles this:

011013C0  call        dword ptr [__imp___errno (11082BCh)] 
011013C6  cmp         esi,esp 
011013C8  call        @ILT+320(__RTC_CheckEsp) (1101145h) 
011013CD  mov         dword ptr [eax],0 

So in my case, the EAX register has the address to set the data breakpoint on. Just check once if your code is similar. Use the @eax pseudo variable in the dialog, like this:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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