Re: svn commit: r240156 - head/lib/libproc

2012-09-06 Thread Rui Paulo
On 6 Sep 2012, at 05:15, Stefan Farfeleder  wrote:

> On Thu, Sep 06, 2012 at 03:19:49AM +, Rui Paulo wrote:
>> @@ -266,7 +268,11 @@ proc_addr2sym(struct proc_handle *p, uin
>>  if (addr >= rsym && addr <= (rsym + sym.st_size)) {
>>  s = elf_strptr(e, dynsymstridx, sym.st_name);
>>  if (s) {
>> -strlcpy(name, s, namesz);
>> +if (strlen(s) > 2 && 
>> +s[0] == '_' && s[1] == 'Z')
>> +__cxa_demangle(s, name, &namesz, NULL);
>> +else
>> +strlcpy(name, s, namesz);
>>  memcpy(symcopy, &sym, sizeof(sym));
>>  /*
>>   * DTrace expects the st_value to contain
> 
> According to the documentation, __cxa_demangle will realloc the buffer
> if it is too small and return the new buffer. This case is not handled
> correctly.


You're right. In fact this happens all the time with libcxxrt.

Thanks,
--
Rui Paulo

___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r240156 - head/lib/libproc

2012-09-06 Thread Rui Paulo
On 6 Sep 2012, at 02:42, Gennady Proskurin  wrote:

> On Thu, Sep 06, 2012 at 03:19:49AM +, Rui Paulo wrote:
>> Author: rpaulo
>> Date: Thu Sep  6 03:19:48 2012
>> New Revision: 240156
>> URL: http://svn.freebsd.org/changeset/base/240156
>> 
>> Log:
>>  Add support for demangling C++ symbols. This requires linking libproc with
>>  libc++rt/libsupc++.
>> 
>>  Discussed with: theraven
>> 
>> Modified:
>>  head/lib/libproc/Makefile
>>  head/lib/libproc/proc_sym.c
>> 
>> Modified: head/lib/libproc/Makefile
>> ==
>> --- head/lib/libproc/MakefileThu Sep  6 02:07:58 2012
>> (r240155)
>> +++ head/lib/libproc/MakefileThu Sep  6 03:19:48 2012
>> (r240156)
>> @@ -1,5 +1,7 @@
>> # $FreeBSD$
>> 
>> +.include 
>> +
>> LIB= proc
>> 
>> SRCS=proc_bkpt.c \
>> @@ -13,6 +15,14 @@ INCS= libproc.h
>> 
>> CFLAGS+= -I${.CURDIR}
>> 
>> +.if ${MK_LIBCPLUSPLUS} != "no"
>> +LDADD+= -lcxxrt
>> +DPADD+= ${LIBCXXRT}
>> +.else
>> +LDADD+= -lsupc++
>> +DPADD+= ${LIBSTDCPLUSPLUS}
>> +.endif
>> +
>> SHLIB_MAJOR= 2
>> 
>> WITHOUT_MAN=
>> 
>> Modified: head/lib/libproc/proc_sym.c
>> ==
>> --- head/lib/libproc/proc_sym.c  Thu Sep  6 02:07:58 2012
>> (r240155)
>> +++ head/lib/libproc/proc_sym.c  Thu Sep  6 03:19:48 2012
>> (r240156)
>> @@ -46,6 +46,8 @@
>> 
>> #include "_libproc.h"
>> 
>> +extern char *__cxa_demangle(const char *, char *, size_t *, int *);
>> +
>> static void  proc_rdl2prmap(rd_loadobj_t *, prmap_t *);
>> 
>> static void
>> @@ -266,7 +268,11 @@ proc_addr2sym(struct proc_handle *p, uin
>>  if (addr >= rsym && addr <= (rsym + sym.st_size)) {
>>  s = elf_strptr(e, dynsymstridx, sym.st_name);
>>  if (s) {
>> -strlcpy(name, s, namesz);
>> +if (strlen(s) > 2 && 
>> +s[0] == '_' && s[1] == 'Z')
> checking "strlen(s) > 2" is useless and not optimal here, you can omit it 
> completely
> checking s[0] and s[1] is enough, it implies that length is >=2
> you may add something like "s[2] != 0" if length should be strictly >2


It's not really useless but can be considered non-optimal, yes. That said, the 
C++ demangler we're calling doesn't really care about being fast :-) 

Regards,
--
Rui Paulo

___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r240156 - head/lib/libproc

2012-09-06 Thread Stefan Farfeleder
On Thu, Sep 06, 2012 at 03:19:49AM +, Rui Paulo wrote:
> @@ -266,7 +268,11 @@ proc_addr2sym(struct proc_handle *p, uin
>   if (addr >= rsym && addr <= (rsym + sym.st_size)) {
>   s = elf_strptr(e, dynsymstridx, sym.st_name);
>   if (s) {
> - strlcpy(name, s, namesz);
> + if (strlen(s) > 2 && 
> + s[0] == '_' && s[1] == 'Z')
> + __cxa_demangle(s, name, &namesz, NULL);
> + else
> + strlcpy(name, s, namesz);
>   memcpy(symcopy, &sym, sizeof(sym));
>   /*
>* DTrace expects the st_value to contain

According to the documentation, __cxa_demangle will realloc the buffer
if it is too small and return the new buffer. This case is not handled
correctly.

Stefan
___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r240156 - head/lib/libproc

2012-09-06 Thread Gennady Proskurin
On Thu, Sep 06, 2012 at 03:19:49AM +, Rui Paulo wrote:
> Author: rpaulo
> Date: Thu Sep  6 03:19:48 2012
> New Revision: 240156
> URL: http://svn.freebsd.org/changeset/base/240156
> 
> Log:
>   Add support for demangling C++ symbols. This requires linking libproc with
>   libc++rt/libsupc++.
>   
>   Discussed with: theraven
> 
> Modified:
>   head/lib/libproc/Makefile
>   head/lib/libproc/proc_sym.c
> 
> Modified: head/lib/libproc/Makefile
> ==
> --- head/lib/libproc/Makefile Thu Sep  6 02:07:58 2012(r240155)
> +++ head/lib/libproc/Makefile Thu Sep  6 03:19:48 2012(r240156)
> @@ -1,5 +1,7 @@
>  # $FreeBSD$
>  
> +.include 
> +
>  LIB= proc
>  
>  SRCS=proc_bkpt.c \
> @@ -13,6 +15,14 @@ INCS=  libproc.h
>  
>  CFLAGS+= -I${.CURDIR}
>  
> +.if ${MK_LIBCPLUSPLUS} != "no"
> +LDADD+=  -lcxxrt
> +DPADD+=  ${LIBCXXRT}
> +.else
> +LDADD+=  -lsupc++
> +DPADD+=  ${LIBSTDCPLUSPLUS}
> +.endif
> +
>  SHLIB_MAJOR= 2
>  
>  WITHOUT_MAN=
> 
> Modified: head/lib/libproc/proc_sym.c
> ==
> --- head/lib/libproc/proc_sym.c   Thu Sep  6 02:07:58 2012
> (r240155)
> +++ head/lib/libproc/proc_sym.c   Thu Sep  6 03:19:48 2012
> (r240156)
> @@ -46,6 +46,8 @@
>  
>  #include "_libproc.h"
>  
> +extern char *__cxa_demangle(const char *, char *, size_t *, int *);
> +
>  static void  proc_rdl2prmap(rd_loadobj_t *, prmap_t *);
>  
>  static void
> @@ -266,7 +268,11 @@ proc_addr2sym(struct proc_handle *p, uin
>   if (addr >= rsym && addr <= (rsym + sym.st_size)) {
>   s = elf_strptr(e, dynsymstridx, sym.st_name);
>   if (s) {
> - strlcpy(name, s, namesz);
> + if (strlen(s) > 2 && 
> + s[0] == '_' && s[1] == 'Z')
checking "strlen(s) > 2" is useless and not optimal here, you can omit it 
completely
checking s[0] and s[1] is enough, it implies that length is >=2
you may add something like "s[2] != 0" if length should be strictly >2

> + __cxa_demangle(s, name, &namesz, NULL);
> + else
> + strlcpy(name, s, namesz);
>   memcpy(symcopy, &sym, sizeof(sym));
>   /*
>* DTrace expects the st_value to contain
> @@ -302,7 +308,11 @@ symtab:
>   if (addr >= rsym && addr <= (rsym + sym.st_size)) {
>   s = elf_strptr(e, symtabstridx, sym.st_name);
>   if (s) {
> - strlcpy(name, s, namesz);
> + if (strlen(s) > 2 && 
> + s[0] == '_' && s[1] == 'Z')
> + __cxa_demangle(s, name, &namesz, NULL);
> + else
> + strlcpy(name, s, namesz);
the same here

>   memcpy(symcopy, &sym, sizeof(sym));
>   /*
>* DTrace expects the st_value to contain
> ___
> svn-src-head@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/svn-src-head
> To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"
> 
___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r240156 - head/lib/libproc

2012-09-05 Thread Rui Paulo
Author: rpaulo
Date: Thu Sep  6 03:19:48 2012
New Revision: 240156
URL: http://svn.freebsd.org/changeset/base/240156

Log:
  Add support for demangling C++ symbols. This requires linking libproc with
  libc++rt/libsupc++.
  
  Discussed with:   theraven

Modified:
  head/lib/libproc/Makefile
  head/lib/libproc/proc_sym.c

Modified: head/lib/libproc/Makefile
==
--- head/lib/libproc/Makefile   Thu Sep  6 02:07:58 2012(r240155)
+++ head/lib/libproc/Makefile   Thu Sep  6 03:19:48 2012(r240156)
@@ -1,5 +1,7 @@
 # $FreeBSD$
 
+.include 
+
 LIB=   proc
 
 SRCS=  proc_bkpt.c \
@@ -13,6 +15,14 @@ INCS=libproc.h
 
 CFLAGS+=   -I${.CURDIR}
 
+.if ${MK_LIBCPLUSPLUS} != "no"
+LDADD+=-lcxxrt
+DPADD+=${LIBCXXRT}
+.else
+LDADD+=-lsupc++
+DPADD+=${LIBSTDCPLUSPLUS}
+.endif
+
 SHLIB_MAJOR=   2
 
 WITHOUT_MAN=

Modified: head/lib/libproc/proc_sym.c
==
--- head/lib/libproc/proc_sym.c Thu Sep  6 02:07:58 2012(r240155)
+++ head/lib/libproc/proc_sym.c Thu Sep  6 03:19:48 2012(r240156)
@@ -46,6 +46,8 @@
 
 #include "_libproc.h"
 
+extern char *__cxa_demangle(const char *, char *, size_t *, int *);
+
 static voidproc_rdl2prmap(rd_loadobj_t *, prmap_t *);
 
 static void
@@ -266,7 +268,11 @@ proc_addr2sym(struct proc_handle *p, uin
if (addr >= rsym && addr <= (rsym + sym.st_size)) {
s = elf_strptr(e, dynsymstridx, sym.st_name);
if (s) {
-   strlcpy(name, s, namesz);
+   if (strlen(s) > 2 && 
+   s[0] == '_' && s[1] == 'Z')
+   __cxa_demangle(s, name, &namesz, NULL);
+   else
+   strlcpy(name, s, namesz);
memcpy(symcopy, &sym, sizeof(sym));
/*
 * DTrace expects the st_value to contain
@@ -302,7 +308,11 @@ symtab:
if (addr >= rsym && addr <= (rsym + sym.st_size)) {
s = elf_strptr(e, symtabstridx, sym.st_name);
if (s) {
-   strlcpy(name, s, namesz);
+   if (strlen(s) > 2 && 
+   s[0] == '_' && s[1] == 'Z')
+   __cxa_demangle(s, name, &namesz, NULL);
+   else
+   strlcpy(name, s, namesz);
memcpy(symcopy, &sym, sizeof(sym));
/*
 * DTrace expects the st_value to contain
___
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"