Re: Customizing variable's summary
Re: Customizing variable's summary
- Subject: Re: Customizing variable's summary
- From: Eric Albert <email@hidden>
- Date: Wed, 12 Nov 2003 02:29:32 -0800
At 11:56 AM -0800 11/11/03, Ricky Sharp wrote:
On Tuesday, November 11, 2003, at 11:05AM, Jim Ingham
<email@hidden> wrote:
If you break in the "// Some code" section, then foo is not going to be
valid yet, but Xcode has no way of knowing that, so we will still call
your data formatter. If the data formatter function crashes with an
access violation, that is okay, gdb can clean up after the call and
return the program to its previous state. But you should be careful
that this is the worst that will happen...
Would it be better than crashing to basically code up an "is pointer
valid" routine? Someone posted to carbon-dev some clever code (that
uses mach-messages?) to see if a pointer is valid within the current
context. Is there perhaps an API that can be called to give us such
functionality, or would each plugin developer potentially need to
roll their own solution?
That "someone" was me, a long time ago. :) I've pasted the code
below. While I can't speak for any of the OS or dev tools teams, I
don't think this would be a good API. It's only a test of whether
the address in question is mapped in your process' address space. If
you're looking at an uninitialized value, sometimes that value will
randomly happen to be in your address space.
That said, here's the code. Use at your own risk. :)
-Eric
#include <stdio.h>
#include <stdlib.h>
#include <mach/mach.h>
int IsPointerValid(const void *ptr) {
kern_return_t result;
vm_address_t address;
vm_size_t size;
struct vm_region_basic_info info;
mach_msg_type_number_t count;
mach_port_t objectName = MACH_PORT_NULL;
address = (vm_address_t) ptr;
count = VM_REGION_BASIC_INFO_COUNT;
result = vm_region(mach_task_self(), &address, &size,
VM_REGION_BASIC_INFO, (vm_region_info_t) &info,
&count, &objectName);
if (objectName != MACH_PORT_NULL) {
mach_port_deallocate(mach_task_self(), objectName);
}
if (result != KERN_SUCCESS || address > (vm_address_t) ptr ||
info.protection == VM_PROT_NONE) {
return 0;
}
return 1;
}
void TestPointer(const void *ptr) {
if (IsPointerValid(ptr)) {
printf("%p is valid!\n", ptr);
} else {
printf("%p is not valid!\n", ptr);
}
}
int main(void) {
int foo;
char *ch;
TestPointer(NULL);
TestPointer(&main);
TestPointer((void *) 0x12345678);
TestPointer(&foo);
TestPointer((void *) 0xffffffff);
ch = (char *) malloc(5);
TestPointer(ch);
return 0;
}
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.