Add libexecinfo from FreeBSD

* Implements backtrace() and a few other functions with the same API as
glibc.
* Useful for porting linux specific things, and for debugging.
This commit is contained in:
Adrien Destugues
2014-04-17 11:11:27 +02:00
parent 0f317c49e9
commit bd8bafd3cd
2 changed files with 150 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
SUMMARY="Library for inspecting program's backtrace"
DESCRIPTION="
This is a quick-n-dirty BSD licensed clone of backtrace facility found
in the GNU libc, mainly intended for porting linuxish code to BSD
platforms, however it can be used at any platform which has a gcc
compiler.
"
HOMEPAGE="http://www.freshports.org/devel/libexecinfo"
COPYRIGHT="2003-2014 Maxim Sobolev"
LICENSE="BSD (2-clause)"
SRC_URI="http://ftp.freebsd.org/pub/FreeBSD/ports/local-distfiles/itetcu/libexecinfo-1.1.tar.bz2"
CHECKSUM_SIZE="4841"
CHECKSUM_RMD160="b2227d4095be0002185b667b9fde71cd876a4ed7"
CHECKSUM_SHA512="51fea7910ef6873061a25c22434ce4da724e9d8e37616a069ad0a58c0463755be4c6c7da88cd747484c2f3373909d7be4678b32a4bd91b6d9e0f74526094e92c"
REVISION="1"
ARCHITECTURES="x86_gcc2"
SECONDARY_ARCHITECTURES="x86"
PROVIDES="
libexecinfo$secondaryArchSuffix = $portVersion compat >= 1
lib:libexecinfo$secondaryArchSuffix = $portVersion compat >= 1
"
REQUIRES="
haiku$secondaryArchSuffix >= $haikuVersion
"
BUILD_REQUIRES="
"
BUILD_PREREQUIRES="
haiku${secondaryArchSuffix}_devel >= $haikuVersion
cmd:gcc$secondaryArchSuffix
cmd:ld$secondaryArchSuffix
cmd:make
"
PATCHES="libexecinfo-$portVersion.patchset"
BUILD()
{
gcc -c -o execinfo.o execinfo.c
gcc -c -o stacktraverse.o stacktraverse.c
ar rcs libexecinfo.a execinfo.o stacktraverse.o
gcc -shared -Wl,-soname,libexecinfo.so.1.1 -o libexecinfo.so execinfo.o stacktraverse.o
}
INSTALL()
{
mkdir -p $libDir
mkdir -p $includeDir
cp libexecinfo.a $libDir
cp libexecinfo.so $libDir
cp execinfo.h $includeDir
prepareInstalledDevelLibs libexecinfo
# devel package
packageEntries devel \
$developDir
}
TEST()
{
gcc test.c -o test libexecinfo.a
./test
}
# ----- devel package -------------------------------------------------------
PROVIDES_devel="
libexecinfo${secondaryArchSuffix}_devel = $portVersion compat >= 1
devel:libexecinfo${secondaryArchSuffix} = $portVersion compat >= 1
"
REQUIRES_devel="
libexecinfo${secondaryArchSuffix} == $portVersion base
"

View File

@@ -0,0 +1,75 @@
From 9618f81449961ea9f5c6d85e45aab86a6b4a16c7 Mon Sep 17 00:00:00 2001
From: Adrien Destugues <pulkomandy@pulkomandy.tk>
Date: Thu, 17 Apr 2014 11:06:49 +0200
Subject: Import FreeBSD patches.
diff --git a/execinfo.c b/execinfo.c
index 906fb14..9448b60 100644
--- a/execinfo.c
+++ b/execinfo.c
@@ -69,7 +69,8 @@ backtrace(void **buffer, int size)
char **
backtrace_symbols(void *const *buffer, int size)
{
- int i, clen, alen, offset;
+ size_t clen, alen;
+ int i, offset;
char **rval;
char *cp;
Dl_info info;
@@ -78,7 +79,6 @@ backtrace_symbols(void *const *buffer, int size)
rval = malloc(clen);
if (rval == NULL)
return NULL;
- (char **)cp = &(rval[size]);
for (i = 0; i < size; i++) {
if (dladdr(buffer[i], &info) != 0) {
if (info.dli_sname == NULL)
@@ -92,14 +92,14 @@ backtrace_symbols(void *const *buffer, int size)
2 + /* " <" */
strlen(info.dli_sname) + /* "function" */
1 + /* "+" */
- D10(offset) + /* "offset */
+ 10 + /* "offset */
5 + /* "> at " */
strlen(info.dli_fname) + /* "filename" */
1; /* "\0" */
rval = realloc_safe(rval, clen + alen);
if (rval == NULL)
return NULL;
- snprintf(cp, alen, "%p <%s+%d> at %s",
+ snprintf((char *) rval + clen, alen, "%p <%s+%d> at %s",
buffer[i], info.dli_sname, offset, info.dli_fname);
} else {
alen = 2 + /* "0x" */
@@ -108,12 +108,15 @@ backtrace_symbols(void *const *buffer, int size)
rval = realloc_safe(rval, clen + alen);
if (rval == NULL)
return NULL;
- snprintf(cp, alen, "%p", buffer[i]);
+ snprintf((char *) rval + clen, alen, "%p", buffer[i]);
}
- rval[i] = cp;
- cp += alen;
+ rval[i] = (char *) clen;
+ clen += alen;
}
+ for (i = 0; i < size; i++)
+ rval[i] += (long) rval;
+
return rval;
}
@@ -155,6 +158,6 @@ backtrace_symbols_fd(void *const *buffer, int size, int fd)
return;
snprintf(buf, len, "%p\n", buffer[i]);
}
- write(fd, buf, len - 1);
+ write(fd, buf, strlen(buf));
}
}
--
1.8.3.4