Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 966
CppLearner Avatar asked Oct 05 '11 07:10

CppLearner


People also ask

What is host physical address?

Physical Address: Refers to the physical address of the Ethernet connection to your computer or server. This may also be referred to as your MAC (Media Access Control) Address, Host ID or Server ID. It is twelve characters long and is a combination of numbers (0–9) and letters (A–F, a–f).

How is physical address generated from virtual address?

This logical address (generated by CPU) combines with the base address generated by the MMU to form the physical address. The hardware device called Memory-Management Unit is used for mapping logical addresses to their corresponding physical address.

What is physical address translation?

Whenever workloads access data in memory, the system needs to look up the physical memory address that matches the virtual address. This is what we refer to as memory translations or mappings. To map virtual memory addresses to physical memory addresses, page tables are used.


2 Answers

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?

like image 153
sinelaw Avatar answered Sep 30 '22 20:09

sinelaw


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.

like image 24
Femaref Avatar answered Sep 30 '22 21:09

Femaref