I may be misunderstanding your question, but what I suspect is that you've misunderstood how sqlite3_open
works.
To call sqlite3_open
you should have a code that looks like this:
sqlite3 * pDB = NULL;
/* ... */
int result = sqlite3_open("file:database.db", &pDB);
As you see, there's no "pointer to pointer" variable in my code. Instead, sqlite3_ope
takes the address of of a pointer variable I allocated on the stack.
To copy that pointer is as simple as:
sqlite3 * pDB2 = pDB
The reason for this is simple:
The sqlite3_open
function wants to return two variable, which is impossible in C.
Instead of returning two variables, sqlite3_open
returns only one variable directly and returns the second variable indirectly.
In order to return the second, it takes a pointer to a variable of the same type it wants to return. Then, by dereferencing the address and filling in the value, it provides you with the second variable's value.
However, the second variable sqlite3_open
returns is a pointer. This is why, in order to return a pointer as a second variable, sqlite3_open
requires a pointer to a pointer variable.
Reading the address
In the example above, the pDB
variable holds the address for the sqlite3 object (the one allocated by sqlite3_open
).
The address, as you know, is simply a number representing a location in the memory. To read the pointer value as a number, simply cast the pointer to a uintptr_t
. i.e.:
uintptr_t db_mem_addr_value = (uintptr_t)pDB;
Of course, numbers (and memory addresses) can't be printed as hex strings directly, they need a function that will convert them into hex notation.
Consider that in C you would print the memory address in Hex notation by using printf
i.e.,
fprintf(stderr, "%p\n", (void *)pDB);
Using dtrace would be the same. You might want to convert the pointer address to a number, for example, using the lltostr
dtrace function:
lltostr((uintptr_t)*(void**)arg1, 16)