0

Is there a way in Visual Studio to debug a function which is only one line?

Something like:

int foo(int a) { return a + 1; }

It seems when VS enters the function, none of the data has been properly initialized, and upon inspecting the variable 'a', I get garbage data. The data is usually initialized once I step to the next line, but since this is a one line function it never seems to do that, which is quite annoying (as I will need to recompile everything just to inspect the value of a).

Andrew
  • 1,355
  • 2
  • 13
  • 28
  • Can you set a breakpoint after the function call instead of where it's declared? – adanot Sep 26 '16 at 20:16
  • I guess that's good enough, although there may be a case where this may not be good enough, but I imagine it would be rare enough to not matter. – Andrew Sep 26 '16 at 20:20
  • Single line function... might also be 3 line function (depends on the codestyle...and I prefer the latter one). But anyway, it makes no difference how the source code was written ... if you don't have it. What are you trying to debug? Do you have any _.pdb_ files? Is this function defined in a _.dll_ that you're calling? If no more info is available I'm afraid you 'll have to dig in (compiler generated) assembly code. – CristiFati Sep 26 '16 at 22:02
  • Using step into (F11) usually works for me, although I admit single line functions are not always easy for the debugger to handle. – Banex Sep 27 '16 at 13:38

2 Answers2

5

If it is simple function, you could start debugging and press Alt+8 for assembly code debug

stryku
  • 722
  • 5
  • 12
4

I don't know if you can step instruction-wise instead of linewise but why don't you just reformat it as

int foo(int a)
{
    return a + 1;
}
merl
  • 162
  • 1
  • 9
  • If I don't have access to the code, then I am unable to do this. – Andrew Sep 26 '16 at 20:19
  • If it's a black box and the post conditions aren't as advertised, you should probably call the original developer. Can you put the problem into context a little? – Robinson Sep 26 '16 at 20:35
  • @Andrew If you don't have access to the code, you won't be able to see it, neither debug it. You can always edit source files and re-compile. Your question does not include much context about possibilities. – Blacktempel Sep 26 '16 at 20:38
  • 1
    Andrew stated in the question that he doesn't want to need to recompile any code. (This answer is painfully obvious, regardless.) – Keith M Sep 26 '16 at 20:39
  • 1
    This doesn't qualify as an answer to the question (even if the question is incomplete). – CristiFati Sep 26 '16 at 22:05