diff options
author | Vas Crabb <vas@vastheman.com> | 2019-11-18 05:08:36 +1100 |
---|---|---|
committer | Vas Crabb <vas@vastheman.com> | 2019-11-18 05:08:36 +1100 |
commit | 88ce545cdda64659894b87fc0b98e1b044eea3e0 (patch) | |
tree | 9a1f05f459b773c70a2ef64443cbe8fee2a3ccd1 /src/emu | |
parent | 1fbfa9e071fe1824ea47c567c23778d8ab33cacf (diff) |
misc cleanup:
* Got rid of some more simple_list in core debugger code
* Fixed a buffer overrun in wavwrite (buffer half requried size)
* Slightly reduced dependencies and overhead in wavwrite
* Made new disassembly windows in Qt debugger default to current CPU
Diffstat (limited to 'src/emu')
-rw-r--r-- | src/emu/debug/debugvw.cpp | 11 | ||||
-rw-r--r-- | src/emu/debug/debugvw.h | 27 | ||||
-rw-r--r-- | src/emu/debug/dvbpoints.cpp | 13 | ||||
-rw-r--r-- | src/emu/debug/dvdisasm.cpp | 13 | ||||
-rw-r--r-- | src/emu/debug/dvdisasm.h | 2 | ||||
-rw-r--r-- | src/emu/debug/dvmemory.cpp | 13 | ||||
-rw-r--r-- | src/emu/debug/dvmemory.h | 2 | ||||
-rw-r--r-- | src/emu/debug/dvstate.cpp | 9 | ||||
-rw-r--r-- | src/emu/debug/dvstate.h | 2 | ||||
-rw-r--r-- | src/emu/debug/dvwpoints.cpp | 15 | ||||
-rw-r--r-- | src/emu/debug/express.cpp | 9 | ||||
-rw-r--r-- | src/emu/debug/express.h | 28 | ||||
-rw-r--r-- | src/emu/debug/textbuf.cpp | 119 |
13 files changed, 121 insertions, 142 deletions
diff --git a/src/emu/debug/debugvw.cpp b/src/emu/debug/debugvw.cpp index f351896480e..f3b71698dbb 100644 --- a/src/emu/debug/debugvw.cpp +++ b/src/emu/debug/debugvw.cpp @@ -32,8 +32,7 @@ //------------------------------------------------- debug_view_source::debug_view_source(const char *name, device_t *device) - : m_next(nullptr), - m_name(name), + : m_name(name), m_device(device) { } @@ -232,10 +231,10 @@ void debug_view::set_source(const debug_view_source &source) const debug_view_source *debug_view::source_for_device(device_t *device) const { - for (debug_view_source &source : m_source_list) - if (device == source.device()) - return &source; - return m_source_list.first(); + for (auto &source : m_source_list) + if (device == source->device()) + return source.get(); + return first_source(); } diff --git a/src/emu/debug/debugvw.h b/src/emu/debug/debugvw.h index 374af7f384e..1386b996b1a 100644 --- a/src/emu/debug/debugvw.h +++ b/src/emu/debug/debugvw.h @@ -13,6 +13,12 @@ #include "express.h" +#include <algorithm> +#include <iterator> +#include <memory> +#include <string> +#include <vector> + //************************************************************************** // CONSTANTS @@ -107,8 +113,6 @@ class debug_view_source { DISABLE_COPYING(debug_view_source); - friend class simple_list<debug_view_source>; - public: // construction/destruction debug_view_source(const char *name, device_t *device = nullptr); @@ -116,14 +120,12 @@ public: // getters const char *name() const { return m_name.c_str(); } - debug_view_source *next() const { return m_next; } device_t *device() const { return m_device; } private: // internal state - debug_view_source * m_next; // link to next item - std::string m_name; // name of the source item - device_t * m_device; // associated device (if applicable) + std::string const m_name; // name of the source item + device_t *const m_device; // associated device (if applicable) }; @@ -149,9 +151,16 @@ public: debug_view_xy cursor_position() { flush_updates(); return m_cursor; } bool cursor_supported() { flush_updates(); return m_supports_cursor; } bool cursor_visible() { flush_updates(); return m_cursor_visible; } + size_t source_count() const { return m_source_list.size(); } const debug_view_source *source() const { return m_source; } - const debug_view_source *first_source() const { return m_source_list.first(); } - const simple_list<debug_view_source> &source_list() const { return m_source_list; } + const debug_view_source *source(unsigned i) const { return (m_source_list.size() > i) ? m_source_list[i].get() : nullptr; } + const debug_view_source *first_source() const { return m_source_list.empty() ? nullptr : m_source_list[0].get(); } + auto source_index(const debug_view_source &source) const + { + const auto it(std::find_if(m_source_list.begin(), m_source_list.end(), [&source] (const auto &x) { return x.get() == &source; })); + return (m_source_list.end() != it) ? std::distance(m_source_list.begin(), it) : -1; + } + const std::vector<std::unique_ptr<const debug_view_source> > &source_list() const { return m_source_list; } // setters void set_visible_size(debug_view_xy size); @@ -188,7 +197,7 @@ protected: debug_view * m_next; // link to the next view debug_view_type m_type; // type of view const debug_view_source *m_source; // currently selected data source - simple_list<debug_view_source> m_source_list; // list of available data sources + std::vector<std::unique_ptr<const debug_view_source> > m_source_list; // list of available data sources // OSD data debug_view_osd_update_func m_osdupdate; // callback for the update diff --git a/src/emu/debug/dvbpoints.cpp b/src/emu/debug/dvbpoints.cpp index d86ce1150cc..51b9fcffcf7 100644 --- a/src/emu/debug/dvbpoints.cpp +++ b/src/emu/debug/dvbpoints.cpp @@ -96,7 +96,7 @@ debug_view_breakpoints::debug_view_breakpoints(running_machine &machine, debug_v { // fail if no available sources enumerate_sources(); - if (m_source_list.count() == 0) + if (m_source_list.empty()) throw std::bad_alloc(); } @@ -118,18 +118,19 @@ debug_view_breakpoints::~debug_view_breakpoints() void debug_view_breakpoints::enumerate_sources() { // start with an empty list - m_source_list.reset(); + m_source_list.clear(); // iterate over devices with disassembly interfaces for (device_disasm_interface &dasm : disasm_interface_iterator(machine().root_device())) { std::string name; name = string_format("%s '%s'", dasm.device().name(), dasm.device().tag()); - m_source_list.append(*global_alloc(debug_view_source(name.c_str(), &dasm.device()))); + m_source_list.emplace_back(std::make_unique<debug_view_source>(name.c_str(), &dasm.device())); } // reset the source to a known good entry - set_source(*m_source_list.first()); + if (!m_source_list.empty()) + set_source(*m_source_list[0]); } @@ -189,10 +190,10 @@ void debug_view_breakpoints::pad_ostream_to_length(std::ostream& str, int len) void debug_view_breakpoints::gather_breakpoints() { m_buffer.resize(0); - for (const debug_view_source &source : m_source_list) + for (auto &source : m_source_list) { // Collect - device_debug &debugInterface = *source.device()->debug(); + device_debug &debugInterface = *source->device()->debug(); for (const device_debug::breakpoint &bp : debugInterface.breakpoint_list()) m_buffer.push_back(&bp); } diff --git a/src/emu/debug/dvdisasm.cpp b/src/emu/debug/dvdisasm.cpp index 667542483a4..f7361ee2229 100644 --- a/src/emu/debug/dvdisasm.cpp +++ b/src/emu/debug/dvdisasm.cpp @@ -52,14 +52,14 @@ debug_view_disasm::debug_view_disasm(running_machine &machine, debug_view_osd_up { // fail if no available sources enumerate_sources(); - if(m_source_list.count() == 0) + if(m_source_list.empty()) throw std::bad_alloc(); // count the number of comments int total_comments = 0; - for(const debug_view_source &source : m_source_list) + for(auto &source : m_source_list) { - const debug_view_disasm_source &dasmsource = downcast<const debug_view_disasm_source &>(source); + const debug_view_disasm_source &dasmsource = downcast<const debug_view_disasm_source &>(*source); total_comments += dasmsource.device()->debug()->comment_count(); } @@ -86,7 +86,7 @@ debug_view_disasm::~debug_view_disasm() void debug_view_disasm::enumerate_sources() { // start with an empty list - m_source_list.reset(); + m_source_list.clear(); // iterate over devices with disassembly interfaces std::string name; @@ -94,11 +94,12 @@ void debug_view_disasm::enumerate_sources() { name = string_format("%s '%s'", dasm.device().name(), dasm.device().tag()); if(dasm.device().memory().space_config(AS_PROGRAM)!=nullptr) - m_source_list.append(*global_alloc(debug_view_disasm_source(name.c_str(), dasm.device()))); + m_source_list.emplace_back(std::make_unique<debug_view_disasm_source>(name.c_str(), dasm.device())); } // reset the source to a known good entry - set_source(*m_source_list.first()); + if (!m_source_list.empty()) + set_source(*m_source_list[0]); } diff --git a/src/emu/debug/dvdisasm.h b/src/emu/debug/dvdisasm.h index ef9e4209f1b..d66f569e050 100644 --- a/src/emu/debug/dvdisasm.h +++ b/src/emu/debug/dvdisasm.h @@ -43,10 +43,10 @@ class debug_view_disasm_source : public debug_view_source { friend class debug_view_disasm; +public: // construction/destruction debug_view_disasm_source(const char *name, device_t &device); -public: // getters address_space &space() const { return m_space; } diff --git a/src/emu/debug/dvmemory.cpp b/src/emu/debug/dvmemory.cpp index 293d1082fc0..282f6a14f3a 100644 --- a/src/emu/debug/dvmemory.cpp +++ b/src/emu/debug/dvmemory.cpp @@ -119,7 +119,7 @@ debug_view_memory::debug_view_memory(running_machine &machine, debug_view_osd_up // fail if no available sources enumerate_sources(); - if (m_source_list.count() == 0) + if (m_source_list.empty()) throw std::bad_alloc(); // configure the view @@ -135,7 +135,7 @@ debug_view_memory::debug_view_memory(running_machine &machine, debug_view_osd_up void debug_view_memory::enumerate_sources() { // start with an empty list - m_source_list.reset(); + m_source_list.clear(); std::string name; // first add all the devices' address spaces @@ -145,14 +145,14 @@ void debug_view_memory::enumerate_sources() { address_space &space = memintf.space(spacenum); name = string_format("%s '%s' %s space memory", memintf.device().name(), memintf.device().tag(), space.name()); - m_source_list.append(*global_alloc(debug_view_memory_source(name.c_str(), space))); + m_source_list.emplace_back(std::make_unique<debug_view_memory_source>(name.c_str(), space)); } // then add all the memory regions for (auto ®ion : machine().memory().regions()) { name = string_format("Region '%s'", region.second->name()); - m_source_list.append(*global_alloc(debug_view_memory_source(name.c_str(), *region.second.get()))); + m_source_list.emplace_back(std::make_unique<debug_view_memory_source>(name.c_str(), *region.second.get())); } // finally add all global array symbols in alphabetical order @@ -174,10 +174,11 @@ void debug_view_memory::enumerate_sources() std::sort(itemnames.begin(), itemnames.end(), [] (auto const &x, auto const &y) { return std::get<0>(x) < std::get<0>(y); }); for (auto const &item : itemnames) - m_source_list.append(*global_alloc(debug_view_memory_source(std::get<0>(item).c_str(), std::get<1>(item), std::get<2>(item), std::get<3>(item)))); + m_source_list.emplace_back(std::make_unique<debug_view_memory_source>(std::get<0>(item).c_str(), std::get<1>(item), std::get<2>(item), std::get<3>(item))); // reset the source to a known good entry - set_source(*m_source_list.first()); + if (!m_source_list.empty()) + set_source(*m_source_list[0]); } diff --git a/src/emu/debug/dvmemory.h b/src/emu/debug/dvmemory.h index dd252af45e9..cae15317575 100644 --- a/src/emu/debug/dvmemory.h +++ b/src/emu/debug/dvmemory.h @@ -27,11 +27,11 @@ class debug_view_memory_source : public debug_view_source { friend class debug_view_memory; +public: debug_view_memory_source(const char *name, address_space &space); debug_view_memory_source(const char *name, memory_region ®ion); debug_view_memory_source(const char *name, void *base, int element_size, int num_elements); -public: address_space *space() const { return m_space; } private: diff --git a/src/emu/debug/dvstate.cpp b/src/emu/debug/dvstate.cpp index e0004f9bb60..4ec9cc3bfa3 100644 --- a/src/emu/debug/dvstate.cpp +++ b/src/emu/debug/dvstate.cpp @@ -55,7 +55,7 @@ debug_view_state::debug_view_state(running_machine &machine, debug_view_osd_upda { // fail if no available sources enumerate_sources(); - if (m_source_list.count() == 0) + if (m_source_list.empty()) throw std::bad_alloc(); } @@ -78,18 +78,19 @@ debug_view_state::~debug_view_state() void debug_view_state::enumerate_sources() { // start with an empty list - m_source_list.reset(); + m_source_list.clear(); // iterate over devices that have state interfaces std::string name; for (device_state_interface &state : state_interface_iterator(machine().root_device())) { name = string_format("%s '%s'", state.device().name(), state.device().tag()); - m_source_list.append(*global_alloc(debug_view_state_source(name.c_str(), state.device()))); + m_source_list.emplace_back(std::make_unique<debug_view_state_source>(name.c_str(), state.device())); } // reset the source to a known good entry - set_source(*m_source_list.first()); + if (!m_source_list.empty()) + set_source(*m_source_list[0]); } diff --git a/src/emu/debug/dvstate.h b/src/emu/debug/dvstate.h index 8239a53f5db..80c3365b17e 100644 --- a/src/emu/debug/dvstate.h +++ b/src/emu/debug/dvstate.h @@ -25,8 +25,10 @@ class debug_view_state_source : public debug_view_source { friend class debug_view_state; +public: // construction/destruction debug_view_state_source(const char *name, device_t &device); + private: // internal state device_state_interface *m_stateintf; // state interface diff --git a/src/emu/debug/dvwpoints.cpp b/src/emu/debug/dvwpoints.cpp index b0584b5d61c..c20332e46eb 100644 --- a/src/emu/debug/dvwpoints.cpp +++ b/src/emu/debug/dvwpoints.cpp @@ -113,7 +113,7 @@ debug_view_watchpoints::debug_view_watchpoints(running_machine &machine, debug_v { // fail if no available sources enumerate_sources(); - if (m_source_list.count() == 0) + if (m_source_list.empty()) throw std::bad_alloc(); } @@ -135,18 +135,19 @@ debug_view_watchpoints::~debug_view_watchpoints() void debug_view_watchpoints::enumerate_sources() { // start with an empty list - m_source_list.reset(); + m_source_list.clear(); + std::string name; // iterate over devices with disassembly interfaces for (device_disasm_interface &dasm : disasm_interface_iterator(machine().root_device())) { - std::string name; name = string_format("%s '%s'", dasm.device().name(), dasm.device().tag()); - m_source_list.append(*global_alloc(debug_view_source(name.c_str(), &dasm.device()))); + m_source_list.emplace_back(std::make_unique<debug_view_source>(name.c_str(), &dasm.device())); } // reset the source to a known good entry - set_source(*m_source_list.first()); + if (!m_source_list.empty()) + set_source(*m_source_list[0]); } @@ -208,10 +209,10 @@ void debug_view_watchpoints::pad_ostream_to_length(std::ostream& str, int len) void debug_view_watchpoints::gather_watchpoints() { m_buffer.resize(0); - for (const debug_view_source &source : m_source_list) + for (auto &source : m_source_list) { // Collect - device_debug &debugInterface = *source.device()->debug(); + device_debug &debugInterface = *source->device()->debug(); for (int spacenum = 0; spacenum < debugInterface.watchpoint_space_count(); ++spacenum) { for (const auto &wp : debugInterface.watchpoint_vector(spacenum)) diff --git a/src/emu/debug/express.cpp b/src/emu/debug/express.cpp index bcd9269db30..45fad747ab3 100644 --- a/src/emu/debug/express.cpp +++ b/src/emu/debug/express.cpp @@ -200,8 +200,7 @@ const char *expression_error::code_string() const //------------------------------------------------- symbol_entry::symbol_entry(symbol_table &table, symbol_type type, const char *name, const std::string &format) - : m_next(nullptr), - m_table(table), + : m_table(table), m_type(type), m_name(name), m_format(format) @@ -560,7 +559,7 @@ void parsed_expression::parse(const char *expression) // copy the string and reset our parsing state m_original_string.assign(expression); m_tokenlist.reset(); - m_stringlist.reset(); + m_stringlist.clear(); // first parse the tokens into the token array in order parse_string_into_tokens(); @@ -1072,7 +1071,7 @@ void parsed_expression::parse_quoted_string(parse_token &token, const char *&str string++; // make the token - token.configure_string(m_stringlist.append(*global_alloc(expression_string(buffer.c_str())))); + token.configure_string(m_stringlist.emplace(m_stringlist.end(), buffer.c_str())->c_str()); } @@ -1089,7 +1088,7 @@ void parsed_expression::parse_memory_operator(parse_token &token, const char *st const char *dot = strrchr(string, '.'); if (dot != nullptr) { - namestring = m_stringlist.append(*global_alloc(expression_string(string, dot - string))); + namestring = m_stringlist.emplace(m_stringlist.end(), string, dot)->c_str(); string = dot + 1; } diff --git a/src/emu/debug/express.h b/src/emu/debug/express.h index ee5a500ad0e..a7147b5dd0f 100644 --- a/src/emu/debug/express.h +++ b/src/emu/debug/express.h @@ -17,6 +17,7 @@ #include <deque> #include <functional> +#include <list> #include <unordered_map> @@ -104,8 +105,6 @@ private: // symbol_entry describes a symbol in a symbol table class symbol_entry { - friend class simple_list<symbol_entry>; - protected: // symbol types enum symbol_type @@ -120,7 +119,6 @@ public: virtual ~symbol_entry(); // getters - symbol_entry *next() const { return m_next; } const char *name() const { return m_name.c_str(); } const std::string &format() const { return m_format; } @@ -134,7 +132,6 @@ public: protected: // internal state - symbol_entry * m_next; // link to next entry symbol_table & m_table; // pointer back to the owning table symbol_type m_type; // type of symbol std::string m_name; // name of the symbol @@ -329,27 +326,6 @@ private: symbol_entry * m_symbol; // symbol pointer }; - // an expression_string holds an indexed string parsed from the expression - class expression_string - { - friend class simple_list<expression_string>; - - public: - // construction/destruction - expression_string(const char *string, int length = 0) - : m_next(nullptr), - m_string(string, (length == 0) ? strlen(string) : length) { } - - // operators - operator const char *() { return m_string.c_str(); } - operator const char *() const { return m_string.c_str(); } - - private: - // internal state - expression_string * m_next; // next string in list - std::string m_string; // copy of the string - }; - // internal helpers void copy(const parsed_expression &src); void print_tokens(FILE *out); @@ -379,7 +355,7 @@ private: symbol_table * m_symtable; // symbol table std::string m_original_string; // original string (prior to parsing) simple_list<parse_token> m_tokenlist; // token list - simple_list<expression_string> m_stringlist; // string list + std::list<std::string> m_stringlist; // string list std::deque<parse_token> m_token_stack; // token stack (used during execution) }; diff --git a/src/emu/debug/textbuf.cpp b/src/emu/debug/textbuf.cpp index 279ce8dead6..48a6f71c5fd 100644 --- a/src/emu/debug/textbuf.cpp +++ b/src/emu/debug/textbuf.cpp @@ -8,9 +8,10 @@ ***************************************************************************/ -#include "corealloc.h" #include "textbuf.h" +#include <new> + /*************************************************************************** @@ -27,47 +28,53 @@ struct text_buffer { - char * buffer; - s32 * lineoffs; - s32 bufsize; - s32 bufstart; - s32 bufend; - s32 linesize; - s32 linestart; - s32 lineend; - u32 linestartseq; - s32 maxwidth; -}; - - - -/*************************************************************************** - INLINE FUNCTIONS -***************************************************************************/ - -/*------------------------------------------------- - buffer_used - return the number of bytes - currently held in the buffer --------------------------------------------------*/ - -static inline s32 buffer_used(text_buffer *text) -{ - s32 used = text->bufend - text->bufstart; - if (used < 0) - used += text->bufsize; - return used; -} - + text_buffer(u32 bytes, u32 lines) noexcept + : buffer(new (std::nothrow) char [bytes]) + , lineoffs(new (std::nothrow) s32 [lines]) + , bufsize(buffer ? bytes : 0) + , linesize(lineoffs ? lines : 0) + { + } + ~text_buffer() + { + if (buffer) + delete [] buffer; + if (lineoffs) + delete [] lineoffs; + } -/*------------------------------------------------- - buffer_space - return the number of bytes - available in the buffer --------------------------------------------------*/ + char *const buffer; + s32 *const lineoffs; + s32 const bufsize; + s32 bufstart = 0; + s32 bufend = 0; + s32 const linesize; + s32 linestart = 0; + s32 lineend = 0; + u32 linestartseq = 0; + s32 maxwidth = 0; + + /*------------------------------------------------- + buffer_used - return the number of bytes + currently held in the buffer + -------------------------------------------------*/ + + s32 buffer_used() const noexcept + { + s32 const used(bufend - bufstart); + return (used < 0) ? (used + bufsize) : used; + } -static inline s32 buffer_space(text_buffer *text) -{ - return text->bufsize - buffer_used(text); -} + /*------------------------------------------------- + buffer_space - return the number of bytes + available in the buffer + -------------------------------------------------*/ + + s32 buffer_space() const noexcept + { + return bufsize - buffer_used(); + } +}; @@ -83,33 +90,19 @@ static inline s32 buffer_space(text_buffer *text) text_buffer *text_buffer_alloc(u32 bytes, u32 lines) { - text_buffer *text; + // allocate memory for the text buffer object + text_buffer *const text(new (std::nothrow) text_buffer(bytes, lines)); - /* allocate memory for the text buffer object */ - text = global_alloc_nothrow(text_buffer); if (!text) return nullptr; - /* allocate memory for the buffer itself */ - text->buffer = global_alloc_array_nothrow(char, bytes); - if (!text->buffer) - { - global_free(text); - return nullptr; - } - - /* allocate memory for the lines array */ - text->lineoffs = global_alloc_array_nothrow(s32, lines); - if (!text->lineoffs) + if (!text->buffer || !text->lineoffs) { - global_free_array(text->buffer); - global_free(text); + delete text; return nullptr; } - /* initialize the buffer description */ - text->bufsize = bytes; - text->linesize = lines; + // initialize the buffer description text_buffer_clear(text); return text; @@ -123,11 +116,7 @@ text_buffer *text_buffer_alloc(u32 bytes, u32 lines) void text_buffer_free(text_buffer *text) { - if (text->lineoffs) - global_free_array(text->lineoffs); - if (text->buffer) - global_free_array(text->buffer); - global_free(text); + delete text; } @@ -186,7 +175,7 @@ void text_buffer_print_wrap(text_buffer *text, const char *data, int wrapcol) needed_space = s32(strlen(data)) + MAX_LINE_LENGTH; /* make space in the buffer if we need to */ - while (buffer_space(text) < needed_space && text->linestart != text->lineend) + while (text->buffer_space() < needed_space && text->linestart != text->lineend) { text->linestartseq++; if (++text->linestart >= text->linesize) |