Sorry, because in previous posts, it seems code was not exactly the same as 
source code.



I now came to the following conclusion:

main (argc=2, argv=0x1032e24) at pgrep.c:935

935             procs = select_procs (&num);

(gdb) s

select_procs (num=0x1032d60) at pgrep.c:489

489     {

(gdb) s

494             pid_t saved_pid = 0;                      /* for new/old 
support */

(gdb) s

495             int matches = 0;

(gdb) s

496             int size = 0;

(gdb) s

498             pid_t myself = getpid();

(gdb) s

499             struct el *list = NULL;

(gdb) p myself

$1 = 19024

(gdb) s

500             long cmdlen = sysconf(_SC_ARG_MAX) * sizeof(char);

(gdb) p _SC_ARG_MAX

$2 = _SC_ARG_MAX

(gdb) p sizeof(char)

$3 = 1

(gdb) p sysconf(_SC_ARG_MAX)

'sysconf' has unknown return type; cast the call to its declared return type

(gdb) s

501             char *cmdline = xmalloc(cmdlen);

(gdb) p cmdlen

$4 = -1

(gdb) 



I am convinced sysconf(_SC_ARG_MAX) returned -1 (I believe in unsigned value 
4294967295)... and it try to allocate that value.

So -1 surely means error for sysconf.



Need to figure out what sysconf(_SC_ARG_MAX) is....



From: https://www.qnx.com/developers/docs/6.4.1/neutrino/lib_ref/s/sysconf.html

_SC_ARG_MAX

Maximum length of arguments for the exec*() functions, 
      in bytes, including environment data.



Now... for the details how I was able to get there... And I feel I may not have 
been doing it the most effective way.

I used info from: https://wiki.debian.org/HowToGetABacktrace

did something like:

#mkdir build_procps

#cd build_procps

#DEB_BUILD_OPTIONS="nostrip noopt" apt -b source procps

root@kibar:~/procps-3.3.16# file /usr/bin/pgrep

/usr/bin/pgrep: ELF 32-bit LSB pie executable, Intel 80386, version 1 (SYSV), 
dynamically linked, interpreter /lib/ld.so, 
BuildID[sha1]=d8ba18308f63edfc63d24003d9dda11fcfa8e75e, for GNU/Hurd 0.0.0, 
with debug_info, not stripped

root@kibar:~/procps-3.3.16# 



[made sure with debug_info, not stripped is there]



#cd some new (empty) directory

#apt-get source procps

# cd procps-3.3.16/



#gdb /usr/bin/pgrep



(gdb) set args something_not_existing

(gdb) break main

(gdb) run

s [for step] repeated many times until I get on the right line, as shown in 
beginning of this message

Reply via email to