From eff7720ae7bb081e3727b14b5450a51d59a2c00d Mon Sep 17 00:00:00 2001 From: Bryce Denney Date: Tue, 19 Nov 2002 09:27:39 +0000 Subject: [PATCH] This fixes bug #640549: dbg fails if wx configured but not on. - The Bochs debugger uses BX_WITH_WX to decide to change to wxWindows debugger behavior: sending a synchronous message to the config interface to get a new command, sending all dbg_printf output to the config interface, deciding whether to trap control-C, etc. But now that it's possible to compile with BX_WITH_WX and BX_WITH_other_things, this isn't quite right anymore. With this change, we now use calls to a new method SIM->is_wx_selected() to decide which behavior to use. This method is equivalent to checking if the display library variable is set to "wx", but it's implemented in such a way that it only has to check a boolean for each call to SIM->is_wx_selected(). - in siminterface.cc, init some local variables to 0 to avoid compile warnings. Modified Files: debug/dbg_main.cc gui/siminterface.cc gui/siminterface.h --- bochs/debug/dbg_main.cc | 54 +++++++++++++------------- bochs/gui/siminterface.cc | 79 +++++++++++++++++++++------------------ bochs/gui/siminterface.h | 3 +- 3 files changed, 70 insertions(+), 66 deletions(-) diff --git a/bochs/debug/dbg_main.cc b/bochs/debug/dbg_main.cc index e52473d6b..47ebacf61 100644 --- a/bochs/debug/dbg_main.cc +++ b/bochs/debug/dbg_main.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: dbg_main.cc,v 1.88 2002-11-19 05:47:44 bdenney Exp $ +// $Id: dbg_main.cc,v 1.89 2002-11-19 09:27:38 bdenney Exp $ ///////////////////////////////////////////////////////////////////////// // // Copyright (C) 2001 MandrakeSoft S.A. @@ -63,7 +63,6 @@ static char tmp_buf[512]; static char *tmp_buf_ptr; static char *argv0 = NULL; - #if BX_NUM_SIMULATORS >= 2 #define BX_DBG_IO_JOURNAL_SIZE 1024 #define BX_DBG_UCMEM_JOURNAL_SIZE 1024 @@ -383,7 +382,6 @@ process_sim2: BX_MEM(1)->load_ROM(bx_options.vgarom.path->getptr (), 0xc0000); #endif - // (mch) Moved from main.cc DEV_init_devices(); DEV_reset_devices(BX_RESET_HARDWARE); @@ -400,10 +398,10 @@ process_sim2: 0); // setup Ctrl-C handler -#if !BX_WITH_WX - signal(SIGINT, bx_debug_ctrlc_handler); - BX_INFO (("set SIGINT handler to bx_debug_ctrlc_handler")); -#endif + if (!SIM->is_wx_selected ()) { + signal(SIGINT, bx_debug_ctrlc_handler); + BX_INFO (("set SIGINT handler to bx_debug_ctrlc_handler")); + } // Print disassembly of the first instruction... you wouldn't think it // would have to be so hard. First initialize guard_found, since it is used @@ -506,8 +504,7 @@ bx_get_command(void) if (bx_infile_stack_index == 0) { sprintf(prompt, " ", bx_infile_stack[bx_infile_stack_index].lineno); } -#if BX_WITH_WX - if (bx_infile_stack_index == 0) { + if (SIM->is_wx_selected() && bx_infile_stack_index == 0) { // wait for wxWindows to send another debugger command charptr_ret = SIM->debug_get_next_command (); if (charptr_ret) { @@ -522,8 +519,8 @@ bx_get_command(void) // shutting down } } -#elif HAVE_LIBREADLINE - if (bx_infile_stack_index == 0) { +#if HAVE_LIBREADLINE + else if (bx_infile_stack_index == 0) { charptr_ret = readline (prompt); // beware, returns NULL on end of file if (charptr_ret && strlen(charptr_ret) > 0) { @@ -533,16 +530,15 @@ bx_get_command(void) free (charptr_ret); charptr_ret = &tmp_buf[0]; } - } else { + } +#endif + else if (bx_infile_stack_index == 0) { + dbg_printf ( "%s", prompt); + } + if (bx_infile_stack_index != 0) { charptr_ret = fgets(tmp_buf, 512, bx_infile_stack[bx_infile_stack_index].fp); } -#else - if (bx_infile_stack_index == 0) - dbg_printf ( "%s", prompt); - charptr_ret = fgets(tmp_buf, 512, - bx_infile_stack[bx_infile_stack_index].fp); -#endif if (charptr_ret == NULL) { // see if error was due to EOF condition if (feof(bx_infile_stack[bx_infile_stack_index].fp)) { @@ -650,18 +646,18 @@ bxerror(char *s) bx_debug_ctrlc_handler(int signum) { UNUSED(signum); -#if BX_WITH_WX - // in a multithreaded environment, a signal such as SIGINT can be sent to all - // threads. This function is only intended to handle signals in the - // simulator thread. It will simply return if called from any other thread. - // Otherwise the BX_PANIC() below can be called in multiple threads at - // once, leading to multiple threads trying to display a dialog box, - // leading to GUI deadlock. - if (!SIM->is_sim_thread ()) { - BX_INFO (("bx_signal_handler: ignored sig %d because it wasn't called from the simulator thread", signum)); - return; + if (SIM->is_wx_selected ()) { + // in a multithreaded environment, a signal such as SIGINT can be sent to all + // threads. This function is only intended to handle signals in the + // simulator thread. It will simply return if called from any other thread. + // Otherwise the BX_PANIC() below can be called in multiple threads at + // once, leading to multiple threads trying to display a dialog box, + // leading to GUI deadlock. + if (!SIM->is_sim_thread ()) { + BX_INFO (("bx_signal_handler: ignored sig %d because it wasn't called from the simulator thread", signum)); + return; + } } -#endif BX_INFO(("Ctrl-C detected in signal handler.")); signal(SIGINT, bx_debug_ctrlc_handler); diff --git a/bochs/gui/siminterface.cc b/bochs/gui/siminterface.cc index bddd8f517..f6ae9dde7 100644 --- a/bochs/gui/siminterface.cc +++ b/bochs/gui/siminterface.cc @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: siminterface.cc,v 1.84 2002-11-19 05:54:25 bdenney Exp $ +// $Id: siminterface.cc,v 1.85 2002-11-19 09:27:38 bdenney Exp $ ///////////////////////////////////////////////////////////////////////// // // See siminterface.h for description of the siminterface concept. @@ -112,6 +112,8 @@ public: virtual int begin_simulation (int argc, char *argv[]); virtual void set_sim_thread_func (is_sim_thread_func_t func) {} virtual bool is_sim_thread (); + bool wxsel; + virtual bool is_wx_selected () { return wxsel; } }; bx_param_c * @@ -198,6 +200,7 @@ bx_real_sim_c::bx_real_sim_c () ci_callback = NULL; ci_callback_data = NULL; is_sim_thread_func = NULL; + wxsel = false; enabled = 1; int i; @@ -302,19 +305,19 @@ bx_real_sim_c::quit_sim (int code) { longjmp (*quit_context, 1); BX_PANIC (("in bx_real_sim_c::quit_sim, longjmp should never return")); } -#if BX_WITH_WX - // in wxWindows, the whole simulator is running in a separate thread. - // our only job is to end the thread as soon as possible, NOT to shut - // down the whole application with an exit. - BX_CPU(0)->async_event = 1; - BX_CPU(0)->kill_bochs_request = 1; - // the cpu loop will exit very soon after this condition is set. -#else - // just a single thread. Use exit() to stop the application. - if (!code) - BX_PANIC (("Quit simulation command")); - ::exit (0); -#endif + if (SIM->is_wx_selected ()) { + // in wxWindows, the whole simulator is running in a separate thread. + // our only job is to end the thread as soon as possible, NOT to shut + // down the whole application with an exit. + BX_CPU(0)->async_event = 1; + BX_CPU(0)->kill_bochs_request = 1; + // the cpu loop will exit very soon after this condition is set. + } else { + // just a single thread. Use exit() to stop the application. + if (!code) + BX_PANIC (("Quit simulation command")); + ::exit (0); + } } int @@ -592,14 +595,14 @@ bx_real_sim_c::create_disk_image ( } void bx_real_sim_c::refresh_ci () { -#if BX_WITH_WX - // presently, only wxWindows interface uses these events - // It's an async event, so allocate a pointer and send it. - // The event will be freed by the recipient. - BxEvent *event = new BxEvent (); - event->type = BX_ASYNC_EVT_REFRESH; - sim_to_ci_event (event); -#endif + if (SIM->is_wx_selected ()) { + // presently, only wxWindows interface uses these events + // It's an async event, so allocate a pointer and send it. + // The event will be freed by the recipient. + BxEvent *event = new BxEvent (); + event->type = BX_ASYNC_EVT_REFRESH; + sim_to_ci_event (event); + } } bx_param_c * @@ -650,18 +653,18 @@ char *bx_real_sim_c::debug_get_next_command () void bx_real_sim_c::debug_puts (const char *text) { -#if BX_WITH_WX - // send message to the wxWindows debugger - BxEvent *event = new BxEvent (); - event->type = BX_ASYNC_EVT_DBG_MSG; - event->u.logmsg.msg = text; - sim_to_ci_event (event); - // the event will be freed by the recipient -#else - // text mode debugger: just write to console - fputs (text, stderr); - delete [] (char *)text; -#endif + if (SIM->is_wx_selected ()) { + // send message to the wxWindows debugger + BxEvent *event = new BxEvent (); + event->type = BX_ASYNC_EVT_DBG_MSG; + event->u.logmsg.msg = text; + sim_to_ci_event (event); + // the event will be freed by the recipient + } else { + // text mode debugger: just write to console + fputs (text, stderr); + delete [] (char *)text; + } } #endif @@ -689,6 +692,10 @@ bx_real_sim_c::configuration_interface(const char *ignore, ci_command_t command) BX_PANIC (("siminterface does not support loading one configuration interface and then calling another")); return -1; } + if (!strcmp (name, "wx")) + wxsel = true; + else + wxsel = false; return (*ci_callback)(ci_callback_data, command); } @@ -966,7 +973,7 @@ bx_shadow_num_c::bx_shadow_num_c (bx_id id, Bit64s bx_shadow_num_c::get64 () { - Bit64u current; + Bit64u current = 0; switch (varsize) { case 8: current = *(val.p8bit); break; case 16: current = *(val.p16bit); break; @@ -987,7 +994,7 @@ bx_shadow_num_c::get64 () { void bx_shadow_num_c::set (Bit64s newval) { - Bit64u tmp; + Bit64u tmp = 0; if (newval < min || newval > max) BX_PANIC (("numerical parameter %s was set to %lld, which is out of range %lld to %lld", get_name (), newval, min, max)); switch (varsize) { diff --git a/bochs/gui/siminterface.h b/bochs/gui/siminterface.h index e9c0ff57e..9ac4f844b 100644 --- a/bochs/gui/siminterface.h +++ b/bochs/gui/siminterface.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////// -// $Id: siminterface.h,v 1.88 2002-11-18 17:16:07 vruppert Exp $ +// $Id: siminterface.h,v 1.89 2002-11-19 09:27:39 bdenney Exp $ ///////////////////////////////////////////////////////////////////////// // // Before I can describe what this file is for, I have to make the @@ -1260,6 +1260,7 @@ public: is_sim_thread_func = func; } virtual bool is_sim_thread () {return true;} + virtual bool is_wx_selected () {return false;} }; BOCHSAPI extern bx_simulator_interface_c *SIM;