5

OS prevents GDB from giving us the physical address, and instead we have virtual addresses. Is there a way to actually get that physical address?

Doing debugging on Windows Visual Studio looks more promising: the addresses look more like real addresses. However, are they really the physical addresses???

I have been investigating GDB and Visual Studio with the following source code for a few days already (and you can tell this from my profile)

int main()
{
  int a = 10;
  int b = 13;
  int c;
  c = a + b;
  return 0;

}

PS: I know I have been asking many similar questions. This is a super broad topic, and I thank you all the great helps. JFYI, it is 3:36AM :( and I do a lot of research + testing before I come here to ask. Thanks.

CppLearner
  • 16,273
  • 32
  • 108
  • 163

3 Answers3

3

You can't, the program and gdb simply don't know about it, which is the point of virtualizing the memory. The operating system takes care of distributing large enough chunks to programs on demand.

Femaref
  • 60,705
  • 7
  • 138
  • 176
  • Thanks for the help. I was told that somehow you could, by using something called "pagemaps"? I think the command is mmap. It was more like an attempt that my friend wanted to try. – CppLearner Oct 05 '11 at 07:48
3

If you mean the actual address on the physical memory hardware, then there isn't really such a thing (consider that the OS may decide to swap your page to disk, etc.)

See here: How to translate a virtual memory address to a physical address?

Community
  • 1
  • 1
sinelaw
  • 16,205
  • 3
  • 49
  • 80
3

If you write a kernel-mode driver for the OS, you'll be able to find out the physical addresses from inside of it. But this most likely isn't practical (it's not easy to code such a driver, the addresses can change due to swapping, and just knowing the addresses is probably of no use either).

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180