Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to capture a SetLastError (VS2008) / debug?

How to capture a SetLastError (VS2008) / debug?

Scheduled Pinned Locked Moved C / C++ / MFC
visual-studiodebuggingtutorialquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Simon Langdon
    wrote on last edited by
    #1

    Something in my app. (C/Win32)is setting SetLastError and I want to debug it, eg capture all calls in my process to this function. Any idea how I'd configure VS to break here? Thanks

    C _ E 3 Replies Last reply
    0
    • S Simon Langdon

      Something in my app. (C/Win32)is setting SetLastError and I want to debug it, eg capture all calls in my process to this function. Any idea how I'd configure VS to break here? Thanks

      C Offline
      C Offline
      Code o mat
      wrote on last edited by
      #2

      Maybe try hooking SetLastError, check out API hooking revealed[^] for details.

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > Sometimes you just have to hate coding to do it well. <

      1 Reply Last reply
      0
      • S Simon Langdon

        Something in my app. (C/Win32)is setting SetLastError and I want to debug it, eg capture all calls in my process to this function. Any idea how I'd configure VS to break here? Thanks

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        This is how I do this - Start Windbg.exe. Open your executable. Set the break point - bp kernel32!SetLastError When it breaks issue any of the stack backtrace commands - k, kp, kP etc.

        «_Superman_» I love work. It gives me something to do between weekends.
        Microsoft MVP (Visual C++)

        1 Reply Last reply
        0
        • S Simon Langdon

          Something in my app. (C/Win32)is setting SetLastError and I want to debug it, eg capture all calls in my process to this function. Any idea how I'd configure VS to break here? Thanks

          E Offline
          E Offline
          Eugen Podsypalnikov
          wrote on last edited by
          #4

          Just call SetLastError(0); by starting of you process. Set a breakpoint there and then - by stopping - take the "Go to Disassembly" from the context menu... Now - step by F10 to "call", then - F11 to "jmp", then - F11 to "mov". Set your second breakpoint here to keep all calls of SetLastError(..) and press F5 to get it :)

          S 1 Reply Last reply
          0
          • E Eugen Podsypalnikov

            Just call SetLastError(0); by starting of you process. Set a breakpoint there and then - by stopping - take the "Go to Disassembly" from the context menu... Now - step by F10 to "call", then - F11 to "jmp", then - F11 to "mov". Set your second breakpoint here to keep all calls of SetLastError(..) and press F5 to get it :)

            S Offline
            S Offline
            Simon Langdon
            wrote on last edited by
            #5

            Thanks for the responses. I managed to find a breakpoint for some function that releases memory. Need to brush up on my assembly perhaps? :-D Not quite what I asked, however a chap at work suggested typing $err into the watch window, this dispays the current value of GetLastError so I can step through code seeing where it changes.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups