Guest User

Untitled

a guest
Feb 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.54 KB | None | 0 0
  1. diff -Nur ocaml-3.11.1.orig/asmrun/fakedebug.c ocaml-3.11.1.fork/asmrun/fakedebug.c
  2. --- ocaml-3.11.1.orig/asmrun/fakedebug.c 1970-01-01 01:00:00.000000000 +0100
  3. +++ ocaml-3.11.1.fork/asmrun/fakedebug.c 2009-10-17 22:13:49.000000000 +0100
  4. @@ -0,0 +1,9 @@
  5. +/* Dummy bytecode debugger values for libraries to use. */
  6. +
  7. +int caml_debugger_in_use = 0;
  8. +int caml_debugger_fork_mode = 1;
  9. +
  10. +void caml_debugger_cleanup_fork(void)
  11. +{
  12. +}
  13. +
  14. diff -Nur ocaml-3.11.1.orig/asmrun/Makefile ocaml-3.11.1.fork/asmrun/Makefile
  15. --- ocaml-3.11.1.orig/asmrun/Makefile 2007-11-15 13:21:15.000000000 +0000
  16. +++ ocaml-3.11.1.fork/asmrun/Makefile 2009-10-17 21:40:41.000000000 +0100
  17. @@ -26,7 +26,7 @@
  18. misc.o freelist.o major_gc.o minor_gc.o memory.o alloc.o compare.o ints.o \
  19. floats.o str.o array.o io.o extern.o intern.o hash.o sys.o parsing.o \
  20. gc_ctrl.o terminfo.o md5.o obj.o lexing.o printexc.o callback.o weak.o \
  21. - compact.o finalise.o custom.o unix.o backtrace.o natdynlink.o
  22. + compact.o finalise.o custom.o unix.o backtrace.o natdynlink.o fakedebug.o
  23.  
  24. ASMOBJS=$(ARCH).o
  25.  
  26. diff -Nur ocaml-3.11.1.orig/byterun/debugger.c ocaml-3.11.1.fork/byterun/debugger.c
  27. --- ocaml-3.11.1.orig/byterun/debugger.c 2008-07-29 09:31:41.000000000 +0100
  28. +++ ocaml-3.11.1.fork/byterun/debugger.c 2009-10-16 11:23:50.000000000 +0100
  29. @@ -35,6 +35,7 @@
  30.  
  31. int caml_debugger_in_use = 0;
  32. uintnat caml_event_count;
  33. +int caml_debugger_fork_mode = 1; /* parent by default */
  34.  
  35. #if !defined(HAS_SOCKETS)
  36.  
  37. @@ -46,6 +47,10 @@
  38. {
  39. }
  40.  
  41. +void caml_debugger_cleanup_fork(void)
  42. +{
  43. +}
  44. +
  45. #else
  46.  
  47. #ifdef HAS_UNISTD
  48. @@ -412,8 +417,19 @@
  49. caml_putword(dbg_out, (Code_val(val)-caml_start_code) * sizeof(opcode_t));
  50. caml_flush(dbg_out);
  51. break;
  52. + case REQ_SET_FORK_MODE:
  53. + caml_debugger_fork_mode = caml_getword(dbg_in);
  54. + break;
  55. }
  56. }
  57. }
  58.  
  59. +void caml_debugger_cleanup_fork(void)
  60. +{
  61. + /* We could remove all of the breakpoints, but closing the connection
  62. + * means that they'll just be skipped anyway. */
  63. + close_connection();
  64. + caml_debugger_in_use = 0;
  65. +}
  66. +
  67. #endif
  68. diff -Nur ocaml-3.11.1.orig/byterun/debugger.h ocaml-3.11.1.fork/byterun/debugger.h
  69. --- ocaml-3.11.1.orig/byterun/debugger.h 2005-09-22 15:21:50.000000000 +0100
  70. +++ ocaml-3.11.1.fork/byterun/debugger.h 2009-10-16 11:23:50.000000000 +0100
  71. @@ -24,6 +24,7 @@
  72. extern int caml_debugger_in_use;
  73. extern int running;
  74. extern uintnat caml_event_count;
  75. +extern int caml_debugger_fork_mode; /* non-zero for parent */
  76.  
  77. enum event_kind {
  78. EVENT_COUNT, BREAKPOINT, PROGRAM_START, PROGRAM_EXIT,
  79. @@ -32,6 +33,7 @@
  80.  
  81. void caml_debugger_init (void);
  82. void caml_debugger (enum event_kind event);
  83. +void caml_debugger_cleanup_fork (void);
  84.  
  85. /* Communication protocol */
  86.  
  87. @@ -84,9 +86,11 @@
  88. REQ_MARSHAL_OBJ = 'M', /* mlvalue v */
  89. /* Send a copy of the data structure rooted at v, using the same
  90. format as [caml_output_value]. */
  91. - REQ_GET_CLOSURE_CODE = 'C' /* mlvalue v */
  92. + REQ_GET_CLOSURE_CODE = 'C', /* mlvalue v */
  93. /* Send the code address of the given closure.
  94. Reply is one uint32. */
  95. + REQ_SET_FORK_MODE = 'K' /* uint32 m */
  96. + /* Set whether to follow the child (m=0) or the parent on fork. */
  97. };
  98.  
  99. /* Replies to a REQ_GO request. All replies are followed by three uint32:
  100. diff -Nur ocaml-3.11.1.orig/debugger/command_line.ml ocaml-3.11.1.fork/debugger/command_line.ml
  101. --- ocaml-3.11.1.orig/debugger/command_line.ml 2009-04-02 10:44:21.000000000 +0100
  102. +++ ocaml-3.11.1.fork/debugger/command_line.ml 2009-10-16 11:23:50.000000000 +0100
  103. @@ -803,6 +803,22 @@
  104. find loading_modes;
  105. fprintf ppf "@."
  106.  
  107. +let follow_fork_variable =
  108. + (function lexbuf ->
  109. + let mode =
  110. + match identifier_eol Lexer.lexeme lexbuf with
  111. + | "child" -> Fork_child
  112. + | "parent" -> Fork_parent
  113. + | _ -> error "Syntax error."
  114. + in
  115. + fork_mode := mode;
  116. + if !loaded then update_follow_fork_mode ()),
  117. + function ppf ->
  118. + fprintf ppf "%s@."
  119. + (match !fork_mode with
  120. + Fork_child -> "child"
  121. + | Fork_parent -> "parent")
  122. +
  123. (** Infos. **)
  124.  
  125. let pr_modules ppf mods =
  126. @@ -1094,7 +1110,14 @@
  127. var_action = integer_variable false 1 "Must be at least 1"
  128. max_printer_steps;
  129. var_help =
  130. -"maximal number of value nodes printed." }];
  131. +"maximal number of value nodes printed." };
  132. + { var_name = "follow_fork_mode";
  133. + var_action = follow_fork_variable;
  134. + var_help =
  135. +"process to follow after forking.\n\
  136. +It can be either :
  137. + child : the newly created process.\n\
  138. + parent : the process that called fork.\n" }];
  139.  
  140. info_list :=
  141. (* info name, function, help *)
  142. diff -Nur ocaml-3.11.1.orig/debugger/debugcom.ml ocaml-3.11.1.fork/debugger/debugcom.ml
  143. --- ocaml-3.11.1.orig/debugger/debugcom.ml 2008-07-29 09:31:41.000000000 +0100
  144. +++ ocaml-3.11.1.fork/debugger/debugcom.ml 2009-10-16 11:23:50.000000000 +0100
  145. @@ -22,8 +22,25 @@
  146.  
  147. let conn = ref Primitives.std_io
  148.  
  149. +(* Set which process the debugger follows on fork. *)
  150. +
  151. +type follow_fork_mode =
  152. + Fork_child
  153. + | Fork_parent
  154. +
  155. +let fork_mode = ref Fork_parent
  156. +
  157. +let update_follow_fork_mode () =
  158. + let a = match !fork_mode with Fork_child -> 0 | Fork_parent -> 1 in
  159. + output_char !conn.io_out 'K';
  160. + output_binary_int !conn.io_out a
  161. +
  162. +(* Set the current connection, and update the fork mode in case it has
  163. + * changed. *)
  164. +
  165. let set_current_connection io_chan =
  166. - conn := io_chan
  167. + conn := io_chan;
  168. + update_follow_fork_mode ()
  169.  
  170. (* Modify the program code *)
  171.  
  172. diff -Nur ocaml-3.11.1.orig/debugger/debugcom.mli ocaml-3.11.1.fork/debugger/debugcom.mli
  173. --- ocaml-3.11.1.orig/debugger/debugcom.mli 2002-10-29 17:53:23.000000000 +0000
  174. +++ ocaml-3.11.1.fork/debugger/debugcom.mli 2009-10-16 11:23:50.000000000 +0100
  175. @@ -32,6 +32,10 @@
  176. Checkpoint_done of int
  177. | Checkpoint_failed
  178.  
  179. +type follow_fork_mode =
  180. + Fork_child
  181. + | Fork_parent
  182. +
  183. (* Set the current connection with the debuggee *)
  184. val set_current_connection : Primitives.io_channel -> unit
  185.  
  186. @@ -76,6 +80,10 @@
  187. (* Set the trap barrier to given stack position. *)
  188. val set_trap_barrier : int -> unit
  189.  
  190. +(* Set whether the debugger follow the child or the parent process on fork *)
  191. +val fork_mode : follow_fork_mode ref
  192. +val update_follow_fork_mode : unit -> unit
  193. +
  194. (* Handling of remote values *)
  195.  
  196. exception Marshalling_error
  197. diff -Nur ocaml-3.11.1.orig/Makefile ocaml-3.11.1.fork/Makefile
  198. --- ocaml-3.11.1.orig/Makefile 2009-05-19 15:46:13.000000000 +0100
  199. +++ ocaml-3.11.1.fork/Makefile 2009-10-18 18:41:55.000000000 +0100
  200. @@ -434,7 +434,7 @@
  201. cd asmrun; $(MAKE) meta.o dynlink.o
  202. $(CAMLOPT) $(LINKFLAGS) -ccopt "$(BYTECCLINKOPTS)" -o ocamlc.opt \
  203. $(COMPOBJS:.cmo=.cmx) \
  204. - asmrun/meta.o asmrun/dynlink.o -cclib "$(BYTECCLIBS)"
  205. + asmrun/meta.o asmrun/dynlink.o asmrun/fakedebug.o -cclib "$(BYTECCLIBS)"
  206. @sed -e 's|@compiler@|$$topdir/ocamlc.opt|' \
  207. driver/ocamlcomp.sh.in > ocamlcomp.sh
  208. @chmod +x ocamlcomp.sh
  209. diff -Nur ocaml-3.11.1.orig/otherlibs/unix/fork.c ocaml-3.11.1.fork/otherlibs/unix/fork.c
  210. --- ocaml-3.11.1.orig/otherlibs/unix/fork.c 2001-12-07 13:40:28.000000000 +0000
  211. +++ ocaml-3.11.1.fork/otherlibs/unix/fork.c 2009-10-17 22:12:30.000000000 +0100
  212. @@ -14,6 +14,7 @@
  213. /* $Id: fork.c,v 1.8 2001/12/07 13:40:28 xleroy Exp $ */
  214.  
  215. #include <mlvalues.h>
  216. +#include <debugger.h>
  217. #include "unixsupport.h"
  218.  
  219. CAMLprim value unix_fork(value unit)
  220. @@ -21,6 +22,10 @@
  221. int ret;
  222. ret = fork();
  223. if (ret == -1) uerror("fork", Nothing);
  224. + if (caml_debugger_in_use)
  225. + if ((caml_debugger_fork_mode && ret == 0) ||
  226. + (!caml_debugger_fork_mode && ret != 0))
  227. + caml_debugger_cleanup_fork();
  228. return Val_int(ret);
  229. }
Add Comment
Please, Sign In to add comment