diff options
author | therealmogminer@gmail.com <therealmogminer@gmail.com> | 2016-06-08 08:10:55 +1000 |
---|---|---|
committer | Vas Crabb <vas@vastheman.com> | 2016-06-08 08:10:55 +1000 |
commit | 56bd36c5ef3960874628bc08cbfcedf4c6057a19 (patch) | |
tree | 3cce04b8c27b773befde51785210bc83673f9fd0 /src/emu/debug/debugcpu.h | |
parent | bf281b3cad1d05c6ef863fa179d3d6ab442a163c (diff) |
Major refactoring of debugger core [Ryan Holtz]
* Eliminate globals/file statics
* Remove lots of stuff from global scope
* Use std::function for custom command registration
* Eliminate some trampolines
* Build fixes from Vas Crabb and balr0g
Diffstat (limited to 'src/emu/debug/debugcpu.h')
-rw-r--r-- | src/emu/debug/debugcpu.h | 195 |
1 files changed, 139 insertions, 56 deletions
diff --git a/src/emu/debug/debugcpu.h b/src/emu/debug/debugcpu.h index 604a6d168b3..2acfba9ea67 100644 --- a/src/emu/debug/debugcpu.h +++ b/src/emu/debug/debugcpu.h @@ -42,6 +42,8 @@ struct xml_data_node; // ======================> device_debug +// [TODO] This whole thing is terrible. + class device_debug { typedef offs_t (*dasm_override_func)(device_t &device, char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, int options); @@ -118,10 +120,10 @@ public: // setters void setEnabled(bool value) { m_enabled = value; } - private: // internals bool hit(int type, offs_t address, int size); + private: const device_debug * m_debugInterface; // the interface we were created from watchpoint * m_next; // next in the list address_space & m_space; // address space @@ -209,6 +211,7 @@ public: void go_exception(int exception); void go_milliseconds(UINT64 milliseconds); void go_next_device(); + template <typename Format, typename... Params> void halt_on_next_instruction(Format &&fmt, Params &&... args) { @@ -278,11 +281,13 @@ public: static const int HISTORY_SIZE = 256; + // debugger_cpu helpers + void compute_debug_flags(); + private: void halt_on_next_instruction_impl(util::format_argument_pack<std::ostream> &&args); // internal helpers - void compute_debug_flags(); void prepare_for_step_overout(offs_t pc); UINT32 dasm_wrapped(std::string &buffer, offs_t pc); @@ -462,100 +467,178 @@ private: DEBUG_FLAG_STOP_INTERRUPT | DEBUG_FLAG_STOP_EXCEPTION | DEBUG_FLAG_STOP_VBLANK | DEBUG_FLAG_STOP_TIME; }; - - //************************************************************************** -// FUNCTION PROTOTYPES +// CPU DEBUGGING //************************************************************************** -/* ----- initialization and cleanup ----- */ +class debugger_cpu +{ +public: + debugger_cpu(running_machine &machine); + + /* ----- initialization and cleanup ----- */ + + /* flushes all traces; this is useful if a trace is going on when we fatalerror */ + void flush_traces(); -/* initialize the CPU tracking for the debugger */ -void debug_cpu_init(running_machine &machine); -void debug_cpu_configure_memory(running_machine &machine, symbol_table &table); + void configure_memory(symbol_table &table); -/* flushes all traces; this is useful if a trace is going on when we fatalerror */ -void debug_cpu_flush_traces(running_machine &machine); + /* ----- debugging status & information ----- */ + /* return the visible CPU device (the one that commands should apply to) */ + device_t *get_visible_cpu(); -/* ----- debugging status & information ----- */ + /* true if the debugger is currently stopped within an instruction hook callback */ + bool within_instruction_hook(); -/* return the visible CPU device (the one that commands should apply to) */ -device_t *debug_cpu_get_visible_cpu(running_machine &machine); + /* return true if the current execution state is stopped */ + bool is_stopped(); -/* TRUE if the debugger is currently stopped within an instruction hook callback */ -int debug_cpu_within_instruction_hook(running_machine &machine); -/* return TRUE if the current execution state is stopped */ -int debug_cpu_is_stopped(running_machine &machine); + /* ----- symbol table interfaces ----- */ + /* return the global symbol table */ + symbol_table *get_global_symtable(); + /* return the locally-visible symbol table */ + symbol_table *get_visible_symtable(); -/* ----- symbol table interfaces ----- */ -/* return the global symbol table */ -symbol_table *debug_cpu_get_global_symtable(running_machine &machine); + /* ----- misc debugger functions ----- */ -/* return the locally-visible symbol table */ -symbol_table *debug_cpu_get_visible_symtable(running_machine &machine); + /* specifies a debug command script to execute */ + void source_script(const char *file); + /* ----- debugger comment helpers ----- */ -/* ----- misc debugger functions ----- */ + // save all comments for a given machine + bool comment_save(); -/* specifies a debug command script to execute */ -void debug_cpu_source_script(running_machine &machine, const char *file); + // load all comments for a given machine + bool comment_load(bool is_inline); + /* ----- debugger memory accessors ----- */ -/* ----- debugger comment helpers ----- */ + /* return the physical address corresponding to the given logical address */ + bool translate(address_space &space, int intention, offs_t *address); -// save all comments for a given machine -bool debug_comment_save(running_machine &machine); + /* return a byte from the specified memory space */ + UINT8 read_byte(address_space &space, offs_t address, int apply_translation); -// load all comments for a given machine -bool debug_comment_load(running_machine &machine,bool is_inline); + /* return a word from the specified memory space */ + UINT16 read_word(address_space &space, offs_t address, int apply_translation); + /* return a dword from the specified memory space */ + UINT32 read_dword(address_space &space, offs_t address, int apply_translation); + /* return a qword from the specified memory space */ + UINT64 read_qword(address_space &space, offs_t address, int apply_translation); -/* ----- debugger memory accessors ----- */ + /* return 1,2,4 or 8 bytes from the specified memory space */ + UINT64 read_memory(address_space &space, offs_t address, int size, int apply_translation); -/* return the physical address corresponding to the given logical address */ -int debug_cpu_translate(address_space &space, int intention, offs_t *address); + /* write a byte to the specified memory space */ + void write_byte(address_space &space, offs_t address, UINT8 data, int apply_translation); -/* return a byte from the specified memory space */ -UINT8 debug_read_byte(address_space &space, offs_t address, int apply_translation); + /* write a word to the specified memory space */ + void write_word(address_space &space, offs_t address, UINT16 data, int apply_translation); -/* return a word from the specified memory space */ -UINT16 debug_read_word(address_space &space, offs_t address, int apply_translation); + /* write a dword to the specified memory space */ + void write_dword(address_space &space, offs_t address, UINT32 data, int apply_translation); -/* return a dword from the specified memory space */ -UINT32 debug_read_dword(address_space &space, offs_t address, int apply_translation); + /* write a qword to the specified memory space */ + void write_qword(address_space &space, offs_t address, UINT64 data, int apply_translation); -/* return a qword from the specified memory space */ -UINT64 debug_read_qword(address_space &space, offs_t address, int apply_translation); + /* write 1,2,4 or 8 bytes to the specified memory space */ + void write_memory(address_space &space, offs_t address, UINT64 data, int size, int apply_translation); -/* return 1,2,4 or 8 bytes from the specified memory space */ -UINT64 debug_read_memory(address_space &space, offs_t address, int size, int apply_translation); + /* read 1,2,4 or 8 bytes at the given offset from opcode space */ + UINT64 read_opcode(address_space &space, offs_t offset, int size); -/* write a byte to the specified memory space */ -void debug_write_byte(address_space &space, offs_t address, UINT8 data, int apply_translation); + // getters + bool within_instruction_hook() const { return m_within_instruction_hook; } + bool memory_modified() const { return m_memory_modified; } + int execution_state() const { return m_execution_state; } + device_t *live_cpu() { return m_livecpu; } + UINT32 get_breakpoint_index() { return m_bpindex++; } + UINT32 get_watchpoint_index() { return m_wpindex++; } + UINT32 get_registerpoint_index() { return m_rpindex++; } + + // setters + void set_visible_cpu(device_t * visiblecpu) { m_visiblecpu = visiblecpu; } + void set_break_cpu(device_t * breakcpu) { m_breakcpu = breakcpu; } + void set_within_instruction(bool within_instruction) { m_within_instruction_hook = within_instruction; } + void set_memory_modified(bool memory_modified) { m_memory_modified = memory_modified; } + void set_execution_state(int execution_state) { m_execution_state = execution_state; } + + // device_debug helpers + // [TODO] [RH]: Look into this more later, can possibly merge these two classes + void start_hook(device_t *device, bool stop_on_vblank); + void stop_hook(device_t *device); + void go_next_device(device_t *device); + void go_vblank(); + void halt_on_next_instruction(device_t *device, util::format_argument_pack<std::ostream> &&args); + void ensure_comments_loaded(); + void reset_transient_flags(); + void process_source_file(); + void watchpoint_check(address_space& space, int type, offs_t address, UINT64 value_to_write, UINT64 mem_mask, device_debug::watchpoint** wplist); + +private: + static const size_t NUM_TEMP_VARIABLES; + + /* expression handlers */ + UINT64 expression_read_memory(void *param, const char *name, expression_space space, UINT32 address, int size); + UINT64 expression_read_program_direct(address_space &space, int opcode, offs_t address, int size); + UINT64 expression_read_memory_region(const char *rgntag, offs_t address, int size); + void expression_write_memory(void *param, const char *name, expression_space space, UINT32 address, int size, UINT64 data); + void expression_write_program_direct(address_space &space, int opcode, offs_t address, int size, UINT64 data); + void expression_write_memory_region(const char *rgntag, offs_t address, int size, UINT64 data); + expression_error::error_code expression_validate(void *param, const char *name, expression_space space); + device_t* expression_get_device(const char *tag); + + /* variable getters/setters */ + UINT64 get_cpunum(symbol_table &table, void *ref); + UINT64 get_beamx(symbol_table &table, void *ref); + UINT64 get_beamy(symbol_table &table, void *ref); + UINT64 get_frame(symbol_table &table, void *ref); + + /* internal helpers */ + void exit(); + void on_vblank(screen_device &device, bool vblank_state); -/* write a word to the specified memory space */ -void debug_write_word(address_space &space, offs_t address, UINT16 data, int apply_translation); + running_machine& m_machine; -/* write a dword to the specified memory space */ -void debug_write_dword(address_space &space, offs_t address, UINT32 data, int apply_translation); + device_t * m_livecpu; + device_t * m_visiblecpu; + device_t * m_breakcpu; -/* write a qword to the specified memory space */ -void debug_write_qword(address_space &space, offs_t address, UINT64 data, int apply_translation); + FILE * m_source_file; // script source file -/* write 1,2,4 or 8 bytes to the specified memory space */ -void debug_write_memory(address_space &space, offs_t address, UINT64 data, int size, int apply_translation); + symbol_table * m_symtable; // global symbol table -/* read 1,2,4 or 8 bytes at the given offset from opcode space */ -UINT64 debug_read_opcode(address_space &space, offs_t offset, int size); + bool m_within_instruction_hook; + bool m_vblank_occurred; + bool m_memory_modified; + bool m_debugger_access; + int m_execution_state; + device_t * m_stop_when_not_device; // stop execution when the device ceases to be this + + UINT32 m_bpindex; + UINT32 m_wpindex; + UINT32 m_rpindex; + + UINT64 m_wpdata; + UINT64 m_wpaddr; + std::unique_ptr<UINT64[]> m_tempvar; + + osd_ticks_t m_last_periodic_update_time; + + bool m_comments_loaded; +}; #endif + |