mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-24 13:53:54 +00:00
Estimated hours taken: 24 Add support to the Mercury tracer for interacting with an external Opium-style debugger via a socket. TODO: currently there is no way for the debugger to specify constraints on the arguments for a `forward_move' query. The current code for doing that doesn't work. (However, the reporting of arguments to the debugger for an `output_current' query works fine.) runtime/mercury_trace.c: Add code to MR_trace() to open a socket connection to an external debugger, and to process requests from that debugger, and send responses back. runtime/mercury_trace.h: runtime/mercury_wrapper.c: Call MR_trace_end() from mercury_runtime_terminate() so that the external debugger gets notified when the program does a (normal) exit. runtime/mercury_stack_layout.h: Fix a bug where the structures here did not match the output produced by compiler/stack_layout.m. library/debugger_interface.m: New file. Declares the Mercury types used for the debugger socket interface and defines support routines used by runtime/mercury_trace.c. library/io.m: runtime/mercury_types.h: Move the definition of MercuryFile from library/io.m to runtime/mercury_types.h, for use by runtime/mercury_trace.c. library/io.m: When printing out values of type `c_pointer', print out the "<<c_pointer>>" string in single quotes, to ensure that it has valid syntax for a Prolog or Mercury term. This is necessary because otherwise c_pointers in procedure arguments could lead to the Mercury process sending a syntactically invalid term down the socket to the debugger, which would then be unable to parse it. library/library.m: Add reference to debugger_interface.m, so that it gets include in libmercury.a. doc/Mmakefile: Make sure that the library/debugger_interface.m does *not* get included in the Mercury library reference manual. runtime/mercury_wrapper.h: runtime/mercury_wrapper.c: runtime/mercury_init.h: util/mkinit.c: Declare, define, and initialize pointers to the C functions exported by library/debugger_interface.m. (This is to avoid having a circular dependency where the runtime depends on the library.) compiler/notes/authors.html: Add Erwan Jahier.
113 lines
3.7 KiB
C
113 lines
3.7 KiB
C
/*
|
|
** Copyright (C) 1993-1998 The University of Melbourne.
|
|
** This file may only be copied under the terms of the GNU Library General
|
|
** Public License - see the file COPYING.LIB in the Mercury distribution.
|
|
*/
|
|
|
|
/*
|
|
** mercury_init.h - this file declares stuff defined in the
|
|
** automatically generated *_init.c files. This is also the interface
|
|
** used by C code that wishes to interface to Mercury.
|
|
**
|
|
** It also declares some stuff that is used in the automatically
|
|
** generate *_init.c files.
|
|
*/
|
|
|
|
#ifndef MERCURY_INIT_H
|
|
#define MERCURY_INIT_H
|
|
|
|
/*
|
|
** The following must come before any definitions of global variables.
|
|
** This is necessary to support DLLs on Windows.
|
|
*/
|
|
#include "mercury_conf.h" /* for USE_DLLS */
|
|
#if USE_DLLS
|
|
#include "libmer_dll.h"
|
|
#endif
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
/*
|
|
** This part is the interface that should be used by C programs that wish
|
|
** to interface to Mercury.
|
|
*/
|
|
|
|
/*
|
|
** mercury_main() is defined in the <module>_init.c file.
|
|
** It calls mercury_init(), mercury_call_main(), and then mercury_terminate().
|
|
*/
|
|
extern int mercury_main(int argc, char **argv);
|
|
|
|
/*
|
|
** mercury_init() is defined in the <module>_init.c file.
|
|
**
|
|
** The `argc' and `argv' parameters are as for main() in C.
|
|
** The `stack_bottom' parameter should be the address of a variable
|
|
** on the C stack. The conservative garbage collector treats that
|
|
** address as the start of the stack, so anything older than that
|
|
** address won't get scanned; don't store pointers to GC'ed memory
|
|
** in local variables that are older than that.
|
|
**
|
|
** mercury_init() just does some stuff to initialize the garbage
|
|
** collector, sets some global variables, and then calls
|
|
** mercury_runtime_init().
|
|
*/
|
|
extern void mercury_init(int argc, char **argv, char *stack_bottom);
|
|
|
|
/*
|
|
** mercury_call_main() is defined in the <module>_init.c file.
|
|
** It just calls mercury_runtime_main(), which calls main/2
|
|
** in the Mercury program.
|
|
*/
|
|
extern void mercury_call_main(void);
|
|
|
|
/*
|
|
** mercury_terminate() is defined in the <module>_init.c file.
|
|
** It just calls mercury_runtime_terminate(), which performs
|
|
** any necessary cleanup, and then returns the appropriate
|
|
** exit status as set by io__set_exit_status.
|
|
*/
|
|
extern int mercury_terminate(void);
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
/*
|
|
** This part defines things which are used by the automatically
|
|
** generated *_init.c file. These should not be used (directly)
|
|
** by C programs that wish to interface to Mercury.
|
|
*/
|
|
|
|
#include "mercury_goto.h" /* for Declare_entry */
|
|
#include "mercury_types.h" /* for `Word' */
|
|
#include "mercury_wrapper.h" /* for do_init_modules,
|
|
mercury_runtime_init(),
|
|
mercury_runtime_main(),
|
|
mercury_runtime_terminate(),
|
|
etc. */
|
|
|
|
#ifdef CONSERVATIVE_GC
|
|
#include "gc.h"
|
|
#endif
|
|
|
|
/*
|
|
** mercury_main() takes the address of the following predicates/functions,
|
|
** which are defined elsewhere.
|
|
*/
|
|
Declare_entry(mercury__main_2_0); /* in the user's program */
|
|
extern void mercury_init_io(void); /* in the Mercury library */
|
|
extern void ML_io_init_state(void); /* in the Mercury library */
|
|
extern void ML_io_finalize_state(void); /* in the Mercury library */
|
|
|
|
/* in library/debugger_interface.m */
|
|
void ML_DI_output_current(Integer, Integer, Integer, Word, String,
|
|
String, Integer, Integer, Integer, Word, String, Word, Word);
|
|
/* normally ML_DI_output_current (output_current/13) */
|
|
bool ML_DI_found_match(Integer, Integer, Integer, Word, String, String,
|
|
Integer, Integer, Integer, Word, String, Word);
|
|
/* normally ML_DI_found_match (found_match/12) */
|
|
void ML_DI_read_request_from_socket(Word, Word *, Integer *);
|
|
|
|
|
|
#endif /* not MERCURY_INIT_H */
|
|
|
|
/*---------------------------------------------------------------------------*/
|