Application of the old Mac-patch (no compilation yet)
--HG-- branch : bgschaidMac
This commit is contained in:
parent
871948d1aa
commit
050ffaab9d
6 changed files with 155 additions and 2 deletions
30
bin/addr2line4Mac.py
Executable file
30
bin/addr2line4Mac.py
Executable file
|
@ -0,0 +1,30 @@
|
|||
#! /usr/bin/python
|
||||
|
||||
import sys
|
||||
filename=sys.argv[1]
|
||||
address=sys.argv[2]
|
||||
import re
|
||||
|
||||
import subprocess
|
||||
|
||||
p = subprocess.Popen("gdb -batch -x /dev/stdin",
|
||||
shell=True,
|
||||
bufsize=0,
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
close_fds=True)
|
||||
|
||||
(child_stdin, child_stdout) = (p.stdin, p.stdout)
|
||||
child_stdin.write("set sharedlibrary preload-libraries no\n")
|
||||
child_stdin.write("file "+filename+"\n")
|
||||
child_stdin.write("info line *"+address+"\n")
|
||||
result=child_stdout.readline()
|
||||
|
||||
answer="??:0"
|
||||
|
||||
match=re.compile('Line (.+) of "(.+)" starts at').match(result)
|
||||
if match:
|
||||
answer=match.group(2)+":"+match.group(1)
|
||||
print answer,
|
||||
|
||||
sys.exit(255)
|
|
@ -18,6 +18,7 @@ FoamFile
|
|||
|
||||
Documentation
|
||||
{
|
||||
// for Macs: docBrowser "open %f";
|
||||
docBrowser "kde-open %f";
|
||||
doxyDocDirs
|
||||
(
|
||||
|
|
|
@ -47,6 +47,10 @@ _foamAddLib()
|
|||
while [ $# -ge 1 ]
|
||||
do
|
||||
export LD_LIBRARY_PATH=$1:$LD_LIBRARY_PATH
|
||||
if [ "$WM_ARCH_BASE" == "darwin" ]
|
||||
then
|
||||
export DYLD_LIBRARY_PATH=$1:$DYLD_LIBRARY_PATH
|
||||
fi
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
|
|
@ -56,11 +56,22 @@ string pOpen(const string &cmd, label line=0)
|
|||
for (label cnt = 0; cnt <= line; cnt++)
|
||||
{
|
||||
char buffer[MAX];
|
||||
|
||||
char* s = fgets(buffer, MAX-1, cmdPipe);
|
||||
|
||||
if (s == NULL)
|
||||
{
|
||||
#ifdef darwin
|
||||
// workaround for the Python-Script
|
||||
for(int i=0;i<MAX;i++) {
|
||||
if(buffer[i]=='\n') {
|
||||
buffer[i]='\0';
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
#else
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
|
||||
if (cnt == line)
|
||||
|
@ -123,7 +134,8 @@ void printSourceFileAndLine
|
|||
#ifndef darwin
|
||||
"addr2line -f --demangle=auto --exe "
|
||||
#else
|
||||
"gaddr2line -f --inline --demangle=auto --exe "
|
||||
// "gaddr2line -f --inline --demangle=auto --exe "
|
||||
"addr2line4Mac.py "
|
||||
#endif
|
||||
+ filename
|
||||
+ " "
|
||||
|
@ -150,6 +162,102 @@ void printSourceFileAndLine
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef darwin
|
||||
|
||||
// Trying to emulate the original backtrace and backtrace_symbol from the glibc
|
||||
// After an idea published by Rush Manbert at http://lists.apple.com/archives/xcode-users/2006/Apr/msg00528.html
|
||||
|
||||
template<int level>
|
||||
void *getStackAddress()
|
||||
{
|
||||
const unsigned int stackLevel=level;
|
||||
return (
|
||||
__builtin_frame_address(level)
|
||||
? __builtin_return_address(stackLevel)
|
||||
: (void *)0
|
||||
);
|
||||
};
|
||||
|
||||
#define GET_STACK_ADDRESS(lvl) \
|
||||
case lvl: {return getStackAddress<lvl>(); break; }
|
||||
|
||||
// please don't laugh. For some reason this is necessary (the compiler won't accept it otherwise)
|
||||
void *getStackAddress(int level)
|
||||
{
|
||||
switch(level) {
|
||||
GET_STACK_ADDRESS(0);
|
||||
GET_STACK_ADDRESS(1);
|
||||
GET_STACK_ADDRESS(2);
|
||||
GET_STACK_ADDRESS(3);
|
||||
GET_STACK_ADDRESS(4);
|
||||
GET_STACK_ADDRESS(5);
|
||||
GET_STACK_ADDRESS(6);
|
||||
GET_STACK_ADDRESS(7);
|
||||
GET_STACK_ADDRESS(8);
|
||||
GET_STACK_ADDRESS(9);
|
||||
GET_STACK_ADDRESS(10);
|
||||
GET_STACK_ADDRESS(11);
|
||||
GET_STACK_ADDRESS(12);
|
||||
GET_STACK_ADDRESS(13);
|
||||
GET_STACK_ADDRESS(14);
|
||||
GET_STACK_ADDRESS(15);
|
||||
GET_STACK_ADDRESS(16);
|
||||
GET_STACK_ADDRESS(17);
|
||||
GET_STACK_ADDRESS(18);
|
||||
GET_STACK_ADDRESS(19);
|
||||
GET_STACK_ADDRESS(20);
|
||||
GET_STACK_ADDRESS(21);
|
||||
default:
|
||||
return (void *)0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned backtrace(void **bt, unsigned maxAddrs)
|
||||
{
|
||||
unsigned valid=0;
|
||||
bool ok=true;
|
||||
|
||||
for(int level=0;level<maxAddrs;level++) {
|
||||
if(ok) {
|
||||
bt[level]=getStackAddress(level);
|
||||
|
||||
if(bt[level]!=(void *)0) {
|
||||
valid=level;
|
||||
} else {
|
||||
ok=false;
|
||||
}
|
||||
} else {
|
||||
bt[level]=(void *)0;
|
||||
}
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
|
||||
// This function is a potential memory leak. But I don't care because the program is terminating anyway
|
||||
char **backtrace_symbols(void **bt,unsigned nr)
|
||||
{
|
||||
char **strings=(char **)malloc(sizeof(char *)*nr);
|
||||
|
||||
for(unsigned i=0;i<nr;i++) {
|
||||
Dl_info info;
|
||||
int result=dladdr(bt[i],&info);
|
||||
|
||||
char tmp[1000];
|
||||
#ifdef darwinIntel64
|
||||
sprintf(tmp,"%s(%s+%p) [%p]",info.dli_fname,info.dli_sname,(void *)((unsigned long)bt[i]-(unsigned long)info.dli_saddr),bt[i]);
|
||||
#else
|
||||
sprintf(tmp,"%s(%s+%p) [%p]",info.dli_fname,info.dli_sname,(void *)((unsigned int)bt[i]-(unsigned int)info.dli_saddr),bt[i]);
|
||||
#endif
|
||||
strings[i]=(char *)malloc(strlen(tmp)+1);
|
||||
strcpy(strings[i],tmp);
|
||||
}
|
||||
|
||||
return strings;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void getSymbolForRaw
|
||||
(
|
||||
|
@ -166,7 +274,8 @@ void getSymbolForRaw
|
|||
#ifndef darwin
|
||||
"addr2line -f --demangle=auto --exe "
|
||||
#else
|
||||
"gaddr2line -f --inline --demangle=auto --exe "
|
||||
// "gaddr2line -f --inline --demangle=auto --exe "
|
||||
"addr2line4Mac.py "
|
||||
#endif
|
||||
+ filename
|
||||
+ " "
|
||||
|
|
|
@ -269,6 +269,8 @@ Foam::label Foam::autoRefineDriver::surfaceOnlyRefine
|
|||
|
||||
const PtrList<featureEdgeMesh> dummyFeatures;
|
||||
|
||||
PtrList<featureEdgeMesh> dummy(0);
|
||||
|
||||
labelList candidateCells
|
||||
(
|
||||
meshRefiner_.refineCandidates
|
||||
|
@ -435,6 +437,8 @@ Foam::label Foam::autoRefineDriver::shellRefine
|
|||
|
||||
const PtrList<featureEdgeMesh> dummyFeatures;
|
||||
|
||||
PtrList<featureEdgeMesh> dummy(0);
|
||||
|
||||
labelList candidateCells
|
||||
(
|
||||
meshRefiner_.refineCandidates
|
||||
|
|
|
@ -173,8 +173,13 @@ libso: $(LIB).$(SO)
|
|||
$(LIB).$(SO): $(OBJECTS)
|
||||
@$(WM_SCRIPTS)/mkObjectDir $(LIB)
|
||||
@rm -f so_locations
|
||||
ifeq ($(WM_ARCH_BASE),darwin)
|
||||
@cd $(OBJECTS_DIR) ; \
|
||||
$(LINKLIBSO) $(LOCAL_OBJECTS) -L$(LIB_WM_OPTIONS_DIR) $(LIB_LIBS) $(GLIB_LIBS) -install_name $(notdir $(LIB)).$(SO) -o $(LIB).$(SO)
|
||||
else
|
||||
@cd $(OBJECTS_DIR) ; \
|
||||
$(LINKLIBSO) $(LOCAL_OBJECTS) -L$(LIB_WM_OPTIONS_DIR) $(LIB_LIBS) $(GLIB_LIBS) -o $(LIB).$(SO)
|
||||
endif
|
||||
|
||||
lib: $(LIB).a
|
||||
@echo \'$(LIB).a\' is up to date.
|
||||
|
|
Reference in a new issue