Subject: bug#36279: 26.2.90; (process-attributes nonexistent-pid) segmentation fault

From: xuchunyang <[email-masked]>
Date: Tue, 18 Jun 2019 22:05:38 +0800

On Tue, Jun 18, 2019, at 9:31 PM, Noam Postavsky wrote:
> Xu Chunyang <[email-masked]> writes:
> 
> > Emacs crashes when I run the following (the PID 123456 doesn't exist)
> >
> >     (process-attributes 123456)
> >
> > And I can reproduce it from Emacs -Q:
> >
> >     ~ $ emacs -Q --batch --eval '(print (process-attributes 123456))'
> >     Fatal error 11: Segmentation faultzsh: segmentation fault  emacs -Q --batch --eval '(print (process-attributes 123456))'
> >     ~ $ emacs --version | head -1
> >     GNU Emacs 26.2.90
> >     ~ $
> >
> >
> > In GNU Emacs 26.2.90 (build 1, x86_64-apple-darwin18.6.0, Carbon Version 158 AppKit 1671.5)
> 
> Doesn't happen here[1], I just get nil.  Can you show a backtrace with a
> gdb (or lldb if that's not available)?

(Not sure what am I doing, never used lldb)

~/src/emacs-mac/src $ lldb ./emacs
(lldb) target create "./emacs"
Current executable set to './emacs' (x86_64).
(lldb) run -Q --batch --eval '(print (process-attributes 123456))'
Process 18581 launched: '/Users/xcy/src/emacs-mac/src/emacs' (x86_64)
emacs was compiled with optimization - stepping may behave oddly; variables may not be available.
Process 18581 stopped
* thread #2, name = 'org.gnu.Emacs.lisp-main', stop reason = EXC_BAD_ACCESS (code=1, address=0x41)
    frame #0: 0x00000001000dd9aa emacs`system_process_attributes(pid=<unavailable>) at sysdep.c:3872:39 [opt]
   3869	  rusage = proc.kp_proc.p_ru;
   3870	  if (rusage)
   3871	    {
-> 3872	      attrs = Fcons (Fcons (Qminflt,  make_fixnum_or_float (rusage->ru_minflt)),
   3873			     attrs);
   3874	      attrs = Fcons (Fcons (Qmajflt,  make_fixnum_or_float (rusage->ru_majflt)),
   3875			     attrs);
Target 0: (emacs) stopped.
(lldb) bt
* thread #2, name = 'org.gnu.Emacs.lisp-main', stop reason = EXC_BAD_ACCESS (code=1, address=0x41)
  * frame #0: 0x00000001000dd9aa emacs`system_process_attributes(pid=<unavailable>) at sysdep.c:3872:39 [opt]
    frame #1: 0x000000010013e854 emacs`eval_sub(form=<unavailable>) at eval.c:2247:41 [opt]
    frame #2: 0x000000010013e7ea emacs`eval_sub(form=<unavailable>) at eval.c:2235:21 [opt]
    frame #3: 0x0000000100141f6b emacs`Feval(form=4370835043, lexical=<unavailable>) at eval.c:2067:28 [opt]
    frame #4: 0x0000000100143b27 emacs`__funcall_subr_block_invoke(.block_descriptor=<unavailable>) at eval.c:0:12 [opt]
    frame #5: 0x00000001001e1a4f emacs`mac_autorelease_loop(body=0x0000000100143a60) at macappkit.m:1040:13 [opt]
    frame #6: 0x0000000100142aff emacs`Ffuncall [inlined] funcall_subr(subr=<unavailable>, numargs=<unavailable>, args=<unavailable>) at eval.c:2909:3 [opt]
    frame #7: 0x0000000100142a99 emacs`Ffuncall(nargs=<unavailable>, args=<unavailable>) at eval.c:2782 [opt]
    frame #8: 0x0000000100186f3e emacs`exec_byte_code(bytestr=<unavailable>, vector=4298690456, maxdepth=<unavailable>, args_template=1030, nargs=1, args=<unavailable>) at bytecode.c:630:12 [opt]
    frame #9: 0x0000000100142a3d emacs`Ffuncall(nargs=<unavailable>, args=<unavailable>) at eval.c:0:4 [opt]
    frame #10: 0x0000000100186f3e emacs`exec_byte_code(bytestr=<unavailable>, vector=4298667856, maxdepth=<unavailable>, args_template=2, nargs=0, args=<unavailable>) at bytecode.c:630:12 [opt]
    frame #11: 0x0000000100142a3d emacs`Ffuncall(nargs=<unavailable>, args=<unavailable>) at eval.c:0:4 [opt]
    frame #12: 0x0000000100186f3e emacs`exec_byte_code(bytestr=<unavailable>, vector=4298664256, maxdepth=<unavailable>, args_template=2, nargs=0, args=<unavailable>) at bytecode.c:630:12 [opt]
    frame #13: 0x0000000100142214 emacs`apply_lambda(fun=4298664181, args=<unavailable>, count=4) at eval.c:2948:9 [opt]
    frame #14: 0x000000010013e610 emacs`eval_sub(form=<unavailable>) at eval.c:0:11 [opt]
    frame #15: 0x0000000100141f6b emacs`Feval(form=4362606819, lexical=<unavailable>) at eval.c:2067:28 [opt]
    frame #16: 0x00000001001410dc emacs`internal_condition_case(bfun=(emacs`top_level_2 at keyboard.c:1118), handlers=22128, hfun=(emacs`cmd_error at keyboard.c:938)) at eval.c:1336:25 [opt]
    frame #17: 0x00000001000d102d emacs`top_level_1(ignore=<unavailable>) at keyboard.c:1127:5 [opt]
    frame #18: 0x00000001001406d0 emacs`internal_catch(tag=53568, func=(emacs`top_level_1 at keyboard.c:1124), arg=0) at eval.c:1101:25 [opt]
    frame #19: 0x00000001000c06ef emacs`command_loop at keyboard.c:1088:2 [opt]
    frame #20: 0x00000001000c060f emacs`recursive_edit_1 at keyboard.c:695:9 [opt]
    frame #21: 0x00000001000c08f6 emacs`Frecursive_edit at keyboard.c:766:3 [opt]
    frame #22: 0x00000001000bf209 emacs`emacs_main(argc=<unavailable>, argv=0x00007ffeefbff7c8) at emacs.c:1759:3 [opt]
    frame #23: 0x000000010020d534 emacs`mac_start_lisp_main(arg=0x00007ffeefbff7c8) at macappkit.m:16723:3 [opt]
    frame #24: 0x00007fff7a9e52eb libsystem_pthread.dylib`_pthread_body + 126
    frame #25: 0x00007fff7a9e8249 libsystem_pthread.dylib`_pthread_start + 66
    frame #26: 0x00007fff7a9e440d libsystem_pthread.dylib`thread_start + 13
(lldb)

> [1]: In GNU Emacs 26.2.90 (build 1, x86_64-pc-linux-gnu, X toolkit, Xaw 
> scroll bars)
> 
>