CppLearner
CppLearner

Reputation: 17040

How can we get the physical address in GDB?

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.

Upvotes: 5

Views: 7791

Answers (3)

Alexey Frunze
Alexey Frunze

Reputation: 62106

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).

Upvotes: 3

sinelaw
sinelaw

Reputation: 16563

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?

Upvotes: 3

Femaref
Femaref

Reputation: 61497

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.

Upvotes: 3

Related Questions