5

I made a simple program in C++ using Visual Studio 2019 to learn. When I open the file with Ghidra, it doesn't seem to detect my functions and I don't know what I'm doing wrong.

My program is simple:

#include <iostream>

void someFunction()
{
    printf("im scared world, i dont understand.\n");
}

int main()
{
    std::cout << "hello world" << '\n';

    someFunction();

    system("pause");

    return 0;
}

Yet the main function looks like this in Ghidra:

int __cdecl _main(int _Argc,char **_Argv,char **_Env)

{
  char cVar1;
  char *unaff_EBP;
  basic_ostream<char,struct_std::char_traits<char>_> *in_stack_fffffff8;

  cVar1 = (char)unaff_EBP;
  operator<<<struct_std::char_traits<char>_>(in_stack_fffffff8,unaff_EBP);
  operator<<<struct_std::char_traits<char>_>(in_stack_fffffff8,cVar1);
                    /* Symbol Ref: No symbol: someFunction */
  _printf("im scared world, i dont understand.\n");
  system("pause");
  return 0;
}

As you can see, where my function should be, it instead shows

/* Symbol Ref: No symbol: someFunction */

Why? What can I do to fix this?

  • 2
    You can tell Visual Studio not to optimize your code and automatically inline function.Use /Od compile parameter. – Robert Feb 11 '20 at 16:33

1 Answers1

9

Visual Studio is inlining the function. You will need to tell VS to not do that:

__declspec(noinline) void someFunction()
{
    printf("im scared world, i dont understand.\n");
}
mumbel
  • 441
  • 3
  • 12