diff --git a/bin/convsym.exe b/bin/convsym.exe index f3a6486d..37bd5d24 100644 Binary files a/bin/convsym.exe and b/bin/convsym.exe differ diff --git a/tools/convsym/CHANGES.md b/tools/convsym/CHANGES.md index d8155acc..ea1a0769 100644 --- a/tools/convsym/CHANGES.md +++ b/tools/convsym/CHANGES.md @@ -1,6 +1,13 @@ # ConvSym version history +### Version 2.12.1 (2024-12-14) + +* `deb2` output format: + - Fixed an edge-case bug where if one block is too large and symbol heap exceeds 64 kb, all further blocks are skipped. + +* Improve README, including some wording and terminology (e.g. "input/output parsers" -> "input/output formats"). + ### Version 2.12 (2024-12-11) * Added support for symbol references instead of raw offsets in `-ref` and `-org` options: @@ -14,7 +21,7 @@ * Added new `txt` input parser to parse arbitrary text files; ConvSym can now parse SGDK's `symbols.txt` file. -* `asm` and `log` output parsers: +* `asm` and `log` output formats: - Implement proper options support in `-outopt`. You can configure line format as `-outopt "/fmt='format-string'"` now (legacy `-outopt "format-string"` syntax is preserved). This goes in line with the new `txt` parser (which also has `/fmt` option among others and will allow to add additional options in the future; - Warn if line format string is incorrect (e.g. too few arguments specified). @@ -24,7 +31,7 @@ * `as_lst_exp` input parser: - Show a warning that `-inopt` is unsupported if user tries to set it. -* `deb2` and `deb1` output parsers: +* `deb2` and `deb1` output formats: - Made tree flattening algorithm introduced in 2.10 deterministic. * Document all default parser options in ConvSym's usage message (printed when invoked without arguments), document `-debug` option. @@ -33,12 +40,12 @@ * Added `-addprefix` option to prepend any string to output symbols. -* `deb2` and `deb1` output parsers: +* `deb2` and `deb1` output formats: - Fixed a rare symbol encoding issue where data with unusual entropy would produce long prefix trees with some codes exceeding 16-bits. Respective characters (usually extremely rare) would then fail to decode properly corrupting a small set of symbol texts. A custom tree rebalancing algorithm was implemented to fix trees with codes longer than 16-bit; - Fixed a minor memory leak (<2 kb in a lifetime) on nodes in encoding function; - Fixed a tiny (several bytes) memory leak due to an unreleased file handle. -* `asm` and `log` output parsers: +* `asm` and `log` output formats: - Properly report I/O error if output file couldn't be opened. ### Version 2.9.1 (2023-03-22) @@ -67,7 +74,7 @@ ### Version 2.7.1 (2022-07-23) -* Fix incorrect newlines produced by `log` and `asm` output parsers on Windows; +* Fix incorrect newlines produced by `log` and `asm` output formats on Windows; * Fix a minor memory leak when a parser crashes; * Overall stability and portability improvements. @@ -75,7 +82,7 @@ * Added support for multiple labels sharing the same offset for all input and output wrappers; -* `deb1` and `deb2` output parsers: +* `deb1` and `deb2` output formats: - Add "/favorLastLabels" option, which toggles choosing last labels when there are multiple labels at the same offset (first labels are preferred otherwise). ### Version 2.6 (2021-02-01) @@ -93,10 +100,10 @@ - Fixed a bug that prevented offsets >=$80000000 to be added due to incorrect signed boundary check; - When several labels occur on the same offset, use the last label met, not the first; - Track last global label name correctly (it previously didn't update the label when it was filtered via boundary or other checks). -* `deb1` output parser: +* `deb1` output format: - Fix memory corruption when symbol map requires more than 64 memory blocks; - Explicitly limit symbols map to 64 blocks, display an error when overflow was about to occur. -* `deb2` output parser: +* `deb2` output format: - Fix infinite loop when the full the last block id was 0xFFFF; - Limit symbols map to 256 blocks, display error if more blocks were requested. diff --git a/tools/convsym/README.md b/tools/convsym/README.md index 7c471d44..0ef3c4cf 100644 --- a/tools/convsym/README.md +++ b/tools/convsym/README.md @@ -13,18 +13,18 @@ The utility supports various input and output processing and transformation opti * [Supported options](#supported-options) * [Examples](#examples) * [Converting SGDK symbols](#converting-sgdk-symbols) -* [Input formats parsers](#input-formats-parsers) - * [`asm68k_sym` parser](#asm68k_sym-parser) - * [`asm68k_lst` parser](#asm68k_lst-parser) - * [`as_lst` parser](#as_lst-parser) - * [`as_lst_exp` parser](#as_lst_exp-parser) - * [`log` parser](#log-input-parser) - * [`txt` parser](#txt-input-parser) -* [Output formats parsers](#output-formats-parsers) - * [`deb2` parser](#deb2-output-parser) - * [`deb1` parser](#deb1-output-parser) - * [`asm` parser](#asm-output-parser) - * [`log` parser](#log-output-parser) +* [Input formats](#input-formats) + * [`asm68k_sym` format](#asm68k_sym-format) + * [`asm68k_lst` format](#asm68k_lst-format) + * [`as_lst` format](#as_lst-format) + * [`as_lst_exp` format](#as_lst_exp-format) + * [`log` format](#log-format) + * [`txt` format](#txt-format) +* [Output formats](#output-formats) + * [`deb2` output format](#deb2-output-format) + * [`deb1` output format](#deb1-output-format) + * [`asm` output format](#asm-output-format) + * [`log` output format](#log-output-format) * [Version history](#version-history) ## Usage @@ -52,7 +52,7 @@ When using `-` as input and/or output file name, the I/O is redirected to STDIN Default: deb2 -inopt [options] - Additional options specific for the input parser. + Additional options specific for the input format. Default options (depending on -in [format]): -in asm68k_sym -inopt "/localSign=@ /localJoin=. /processLocals+" -in asm68k_lst -inopt "/localSign=@ /localJoin=. /ignoreMacroDefs+ /ignoreMacroExp- /addMacrosAsOpcodes+ /processLocals+" @@ -61,7 +61,7 @@ When using `-` as input and/or output file name, the I/O is redirected to STDIN -in txt -inopt "/fmt='%s %X' /offsetFirst-" -outopt [options] - Additional options specific for the output parser. + Additional options specific for the output format. Default options (depending on -out [format]): -out deb2 -outopt "/favorLastLabels-" -out deb1 -outopt "/favorLastLabels-" @@ -135,7 +135,7 @@ Symbols conversion and filtering options: ### Examples -**Default options.** Converts ASM68K symbol file to DEB2 format (implies `-input asm68k_sym` and `-output deb2` for default parsers respectively): +**Default options.** Converts ASM68K symbol file to DEB2 format (implies `-input asm68k_sym` and `-output deb2` for Defaults respectively): ```sh convsym symbols.sym symbols.deb2 @@ -163,7 +163,7 @@ convsym symbols.log rom.bin -input log -a -filter "z80.+" -exclude -tolower -ref Since **version 2.11** ConvSym supports converting symbols in SGDK projects. -SGDK logs all symbols to `symbol.txt` file upon build. Since version 2.11 ConvSym introduced `txt` input parser which can be configured to recognize this file's format. +SGDK logs all symbols to `symbol.txt` file upon build. Since version 2.11 ConvSym introduced `txt` input format which can be configured to recognize this file's format. Here's how ConvSym can be invoked in the command line to store symbols from `out/symbol.txt` file in `out/rom.bin`: @@ -174,8 +174,8 @@ convsym out/symbol.txt out/rom.bin -in txt -inopt "/fmt='%X %*[TtBbCcDd] %511s / Let's break down command line options: - `out/symbol.txt out/rom.bin` - specifies path to input and output files respectively; -- `-in txt` - selects `txt` parser for the input file; -- `-inopt "/fmt='%X %*[TtBbCcDd] %511s /offsetFirst+"` - specifies `/fmt` and `/offsetFirst` options for the parser (they are exclusive to `txt` parser), `/fmt` describes line format for the file, which includes: +- `-in txt` - selects `txt` format for the input file; +- `-inopt "/fmt='%X %*[TtBbCcDd] %511s /offsetFirst+"` - specifies `/fmt` and `/offsetFirst` format options (they are exclusive to `txt` format), `/fmt` describes line format for the file, which includes: - A hex offset (`%X`); - One of the following symbol type specifiers `T`, `t`, `B`, `b`, `C`, `c`, `D`, `d` (others are ignored); - A label name which shouldn't exceed 512 characters with null terminator (`%511s`); @@ -185,19 +185,20 @@ Let's break down command line options: - `-ref @MDDBG__SymbolTablePtr` - writes reference pointer to the symbol table (where ROM was appended) at offset specified by the `MDDBG__SymbolTablePtr` symbol in ROM so MD Debugger can read it (**WARNING!** Make sure this symbol exists, or ConvSym will fail). -## Input formats parsers +## Input formats -Summary of currently supported input formats and their respective parsers (input data format can be specified via `-input` option, or its shorthand: `-in`): +Summary of currently supported input formats (input data format can be specified via `-input` option, or its shorthand: `-in`): * `asm68k_sym`, `asm68k_lst` - **ASM68K** assembler symbol and listing files; * `as_lst`, `as_lst_exp` - **The AS Macro Assembler** listing files (*stable* since **version 2.8**, and *experimental*); -* `log` - Plain-text symbol tables (since **version 2.1**). +* `log` - Plain-text symbol tables (since **version 2.1**); +* `txt` - Generic text format parser with configurable format string (since **version 2.12**). -Some parsers support additional options, which can be specified via `-inopt` option. These options are described below. +Some formats support additional options, which can be specified via `-inopt` option. These options are described below. -### `asm68k_sym` parser +### `asm68k_sym` format -This parser expects a symbol file produced by the **ASM68K** assembler for input. It's the recommended parser for projects using **ASM68K**. +Expects a symbol file produced by the **ASM68K** assembler for input. It's the recommended input format for projects using **ASM68K**. It also supports local symbols, if produced by the assembler. @@ -207,7 +208,7 @@ It also supports local symbols, if produced by the assembler. **Options:** -Since **version 2.6**, this parser supports the following options: +Since **version 2.6**, the following options are supported: ``` /localSign=[x] @@ -221,13 +222,13 @@ Since **version 2.6**, this parser supports the following options: options have no effect) ``` -Default parser options can be expressed as follows: +Default options can be expressed as follows: -inopt "/localSign=@ /localJoin=. /processLocals+" -### `asm68k_lst` parser +### `asm68k_lst` format -This parser expects a listing file produced by the **ASM68K** assembler for input. Local symbols are also supported by default. +Expects a listing file produced by the **ASM68K** assembler for input. Local symbols are also supported by default. Since parsing of listing files is less reliable, symbol files and `asm68_sym` format is recommended instead (see above). > [!NOTE] > @@ -235,9 +236,9 @@ This parser expects a listing file produced by the **ASM68K** assembler for inpu **Known issues**: -* The parser will ignore line break character `&`, as line continuations aren't properly listed by the **ASM68K** assembler; some information may be lost. +* The format will ignore line break character `&`, as line continuations aren't properly listed by the **ASM68K** assembler; some information may be lost. * Labels before the `if` directive (and its derivatives) may not be included in the listing file due to the assembler bug, hence they will be missing from the symbols table generated by **ConvSym**. -* Parser doesn't tolerate `SECTION` directives in the listing files, as assembler generates incorrect offsets whenever they are used; expect a lot of missing or misplaced symbols if you use them. The fix for this cannot be provided in the current implementation of the parser. +* format doesn't tolerate `SECTION` directives in the listing files, as assembler generates incorrect offsets whenever they are used; expect a lot of missing or misplaced symbols if you use them. The fix for this cannot be provided in the current implementation of the format. **Options:** @@ -263,14 +264,14 @@ This parser expects a listing file produced by the **ASM68K** assembler for inpu specify whether local labels will processed; default: + ``` -Default parser options can be expressed as follows: +Default options can be expressed as follows: -inopt "/localSign=@ /localJoin=. /ignoreMacroDefs+ /ignoreMacroExp- /addMacrosAsOpcodes+ /processLocals+" -### `as_lst` parser +### `as_lst` format -This parser expects a listing file produced by the **AS** assembler for input. It's the recommended parser for projects using **AS**. +Expects a listing file produced by the **AS** assembler for input. It's the recommended format for projects using **AS**. Since version **version 2.8**, it works by processing a symbol table at the end of the file. This parser superseded the old experimental one, which is now available as `as_lst_exp` (so if you're looking for pre-v2.8 behaviour for some reason, use that instead). @@ -282,7 +283,7 @@ It also supports local symbols, if produced by the assembler. **Options:** -Since **version 2.8**, this parser supports the following options: +Since **version 2.8**, the following options are supported: ``` /localJoin=[x] @@ -297,27 +298,27 @@ Since **version 2.8**, this parser supports the following options: place of nameless labels (+, - etc) ``` -Default parser options can be expressed as follows: +Default options can be expressed as follows: -inopt "/localJoin=. /processLocals+ /ignoreInternalSymbols+" -### `as_lst_exp` parser +### `as_lst_exp` format -*This parser is available since **version 2.8**.* +*Available since **version 2.8**.* -This is an experimental version of listing files parser for the AS assembler. Like `as_lst` parser, it expects a listing file produced by the **AS** assembler for input. +This is an experimental version of listing files parser for the AS assembler. Like `as_lst` format, it expects a listing file produced by the **AS** assembler for input. Using this parser is currently not recommended and its implementation may drastically change in future versions of ConvSym. -Before **version 2.8** it was actually in place of the `as_lst` parser, but the latter has since been replaced with a more stable and refined implementation. +Before **version 2.8** it was actually in place of the `as_lst` format, but the latter has since been replaced with a more stable and refined implementation. -### `log` input parser +### `log` format -*This parser is available since **version 2.1**.* +*Available since **version 2.1**.* -This parser expects a plain-text file, where each row logs an individual symbol name and its offset, in order. +Expects a plain-text file, where each row logs an individual symbol name and its offset, in order. The default format is the following: @@ -337,17 +338,17 @@ Whitespaces and tabulation are ignored and don't affect parsing. sets whether offsets should be parsed as decimal numbers; default: - ``` -Default parser options can be expressed as follows: +Default options can be expressed as follows: -inopt "/separator=: /useDecimal-" -### `txt` input parser +### `txt` format -*This parser is available since **version 2.11**.* +*Available since **version 2.11**.* -This parser aims for generic text files and can be flexibly configured for arbitrary line formats using `printf`-like syntax (`scanf` format from the C standard library to be exact). It defaults to `%s %X` (e.g. `MyLabel 1C2`). +Used for generic text files and can be flexibly configured for arbitrary line formats using `printf`-like syntax (`scanf` format from the C standard library to be exact). It defaults to `%s %X` (e.g. `MyLabel 1C2`). -This parser can be used to parse SGDK's `symbols.txt` file (see [Converting SGDK symbols](#converting-sgdk-symbols) section). +With additional configuration it can be used to parse SGDK's `symbols.txt` file (see [Converting SGDK symbols](#converting-sgdk-symbols) section). **Options:** @@ -359,27 +360,27 @@ This parser can be used to parse SGDK's `symbols.txt` file (see [Converting SGDK specifies whether offset comes first in the input string; default: - ``` -Default parser options can be expressed as follows: +Default options can be expressed as follows: -inopt "/fmt='%s %X' /offsetFirst-" -## Output formats parsers +## Output formats -Summary of currently supported output formats and their respective parsers (output data format can be specified via `-output` option, or its shorthand: `-out`): +Summary of currently supported output formats (output data format can be specified via `-output` option, or its shorthand: `-out`): * `deb2` - Debug symbols database format for "The Advanced Error Handler and Debugger 2.x"; * `deb1` - Debug symbols database format for "The Advanced Error Handler and Debugger 1.x"; * `asm`, `log` - Plain-text **.asm** and **.log**/**.txt** files. -Some parsers support additional options, which can be specified via `-outopt` option. These options are described below. +Some formats support additional options, which can be specified via `-outopt` option. These options are described below. -### `deb2` output parser +### `deb2` output format -This parser outputs debug symbols database in DEB2 format, which is the format supported by the "The Advanced Error Handler and Debugger". This is the default output parser. +Outputs debug symbols database in DEB2 format, which is the format supported by the MD Debugger and Error Handler. This is the default output format. **Options:** -Since **version 2.7**, this parser supports the following options: +Since **version 2.7**, the following options are supported: ``` /favorLastLabels[+|-] @@ -387,17 +388,17 @@ Since **version 2.7**, this parser supports the following options: the same offset (the first processed label is chosen otherwise); default: - ``` -Default parser options can be expressed as follows: +Default options can be expressed as follows: -outopt "/favorLastLabels-" -### `deb1` output parser +### `deb1` output format -This parser outputs debug symbols database in old DEB1 format. This is an outdated and limited format which is not supported by the current version of "The Advanced Error Handler and Debugger". This parser only aims to retain compatibility with the Error Handler 1.0. +Outputs debug symbols database in old DEB1 format. This is an outdated and limited format which is not supported by the current version of MD Debugger and Error Handler. This format only aims to retain compatibility with the Error Handler 1.0. **Options:** -Since **version 2.7**, this parser supports the following options: +Since **version 2.7**, the following options are supported: ``` /favorLastLabels[+|-] @@ -405,14 +406,14 @@ Since **version 2.7**, this parser supports the following options: the same offset (the first processed label is chosen otherwise); default: - ``` -Default parser options can be expressed as follows: +Default options can be expressed as follows: -outopt "/favorLastLabels-" -### `asm` output parser +### `asm` output format -By default, this parser produces a symbol list in assembly format recognized by both **ASM68K** and **AS** assemblers. +By default, outputs a symbol list in assembly format recognized by both **ASM68K** and **AS** assemblers. The default format is the following: @@ -424,14 +425,14 @@ This format can be altered by passing **printf**-compatible format string, where **Options:** -Since **version 2.11**, this parser supports the following options: +Since **version 2.11**, the following options are supported: ``` /fmt='format-string' specifies format string to print (label, offset) pairs, default: "%s: equ $%X" ``` -Default parser options can be expressed as follows: +Default options can be expressed as follows: -outopt "/fmt='%s: equ $%X'" @@ -440,9 +441,9 @@ Before **version 2.11** format string option could be specified as follows (this -outopt "%s: equ $%X" -### `log` output parser +### `log` output format -By default, this parser produces symbol list in plain-text format that is compatible with the input parser of the same name (see "`log` input parser"). +By default, outputs symbol list in plain-text format that is compatible with the input format of the same name (see "`log` input format"). The default format is the following: @@ -454,14 +455,14 @@ This format can be altered by passing **printf**-compatible format string, where **Options:** -Since **version 2.11**, this parser supports the following options: +Since **version 2.11**, the following options are supported: ``` /fmt='format-string' specifies format string to print (offset, label) pairs, default: "%X: %s" ``` -Default parser options can be expressed as follows: +Default options can be expressed as follows: -outopt "/fmt='%X: %s'" diff --git a/tools/convsym/src/main.cpp b/tools/convsym/src/main.cpp index d88d69b3..6c4b6110 100644 --- a/tools/convsym/src/main.cpp +++ b/tools/convsym/src/main.cpp @@ -31,7 +31,7 @@ int main (int argc, const char ** argv) { /* Provide help if no sufficient arguments were passed */ if (argc<2) { printf( - "ConvSym utility version 2.12\n" + "ConvSym utility version 2.12.1\n" "(c) 2016-2024, vladikcomper\n" "\n" "Command line arguments:\n" @@ -55,7 +55,7 @@ int main (int argc, const char ** argv) { " Default: deb2\n" "\n" " -inopt [options]\n" - " Additional options specific for the input parser. See README for more information.\n" + " Additional options specific for the input format. See README for more information.\n" " Default options (depending on -in [format]):\n" " -in asm68k_sym -inopt \"/localSign=@ /localJoin=. /processLocals+\"\n" " -in asm68k_lst -inopt \"/localSign=@ /localJoin=. /ignoreMacroDefs+ /ignoreMacroExp- /addMacrosAsOpcodes+ /processLocals+\"\n" @@ -64,7 +64,7 @@ int main (int argc, const char ** argv) { " -in txt -inopt \"/fmt='%%s %%X' /offsetFirst-\"\n" "\n" " -outopt [options]\n" - " Additional options specific for the output parser. See README for more information.\n" + " Additional options specific for the output format. See README for more information.\n" " Default options (depending on -out [format]):\n" " -out deb2 -outopt \"/favorLastLabels-\"\n" " -out deb1 -outopt \"/favorLastLabels-\"\n" diff --git a/tools/convsym/src/output/DEB1.cpp b/tools/convsym/src/output/DEB1.cpp index 0013eec4..aee430c5 100644 --- a/tools/convsym/src/output/DEB1.cpp +++ b/tools/convsym/src/output/DEB1.cpp @@ -4,6 +4,7 @@ * Output wrapper for the Debug Information format version 1.0 * * ------------------------------------------------------------ */ +#include #include #include #include @@ -26,13 +27,15 @@ struct Output__Deb1 : public OutputWrapper { * Main function that generates the output */ void parse( - std::multimap& SymbolList, + std::multimap& symbols, const char * fileName, uint32_t appendOffset = 0, uint32_t pointerOffset = 0, const char * opts = "", bool alignOnAppend = true ) { + assert(!symbols.empty()); + auto output = OutputWrapper::setupOutput(fileName, appendOffset, pointerOffset, alignOnAppend); /* Parse options from "-inopt" agrument's value */ @@ -49,7 +52,7 @@ struct Output__Deb1 : public OutputWrapper { output->writeBEWord(0xDEB1); /* Allocate space for blocks offsets table */ - auto lastSymbolPtr = SymbolList.rbegin(); + auto lastSymbolPtr = symbols.rbegin(); uint16_t lastBlock = (lastSymbolPtr->first) >> 16; if (lastBlock > 63) { // blocks index table is limited to $40 entries (which is only enough to ROM section) @@ -71,7 +74,7 @@ struct Output__Deb1 : public OutputWrapper { /* Generate table of character frequencies based on symbol names */ uint32_t freqTable[0x100] = { 0 }; - for ( auto& symbol : SymbolList ) { + for (auto& symbol : symbols) { for (auto& character : symbol.second) { freqTable[(int)character]++; } @@ -96,15 +99,15 @@ struct Output__Deb1 : public OutputWrapper { /* ------------------------------------- */ { - IO::Log( IO::debug, "Generating symbol data blocks..."); + IO::Log(IO::debug, "Generating symbol data blocks..."); - auto SymbolPtr = SymbolList.begin(); + auto symbolPtr = symbols.begin(); /* For 64kb block within symbols range */ for (uint16_t block = 0x00; block <= lastBlock; block++) { /* Align block on even address */ - if ( output->getCurrentOffset() & 1 ) { + if (output->getCurrentOffset() & 1) { output->writeByte(0x00); } @@ -115,47 +118,50 @@ struct Output__Deb1 : public OutputWrapper { std::vector symbolsData; /* For every symbol within the block ... */ - for (; block == (SymbolPtr->first>>16) && (SymbolPtr != SymbolList.cend()); ++SymbolPtr) { - IO::Log( IO::debug, "\t%08X\t%s", SymbolPtr->first, SymbolPtr->second.c_str() ); + for (; (symbolPtr->first>>16) <= block && (symbolPtr != symbols.cend()); ++symbolPtr) { + if ((symbolPtr->first>>16) < block) { + continue; + } + + IO::Log( IO::debug, "\t%08X\t%s", symbolPtr->first, symbolPtr->second.c_str() ); /* * For records with the same offsets, fetch only the last or the first processed symbol, * depending "favor last labels" option ... */ - if ( (optFavorLastLabels && std::next(SymbolPtr) != SymbolList.end() - && std::next(SymbolPtr)->first == SymbolPtr->first) || - (!optFavorLastLabels && SymbolPtr != SymbolList.begin() - && std::prev(SymbolPtr)->first == SymbolPtr->first) ) { + if ( (optFavorLastLabels && std::next(symbolPtr) != symbols.end() + && std::next(symbolPtr)->first == symbolPtr->first) || + (!optFavorLastLabels && symbolPtr != symbols.begin() + && std::prev(symbolPtr)->first == symbolPtr->first) ) { continue; } - BitStream SymbolsHeap; + BitStream symbolHeap; /* Add offset to the offsets block */ - offsetsData.push_back(swap16((uint16_t)SymbolPtr->first & 0xFFFF)); + offsetsData.push_back(swap16((uint16_t)symbolPtr->first & 0xFFFF)); /* Encode each symbol character with the generated Huffman-codes and store it in the bitsteam */ - for (auto& Character : SymbolPtr->second) { + for (auto& Character : symbolPtr->second) { auto *record = characterToRecord[(int)Character]; - SymbolsHeap.pushCode(record->code, record->codeLength); + symbolHeap.pushCode(record->code, record->codeLength); } /* Finally, add null-terminator */ { auto *record = characterToRecord[0x00]; - SymbolsHeap.pushCode(record->code, record->codeLength); + symbolHeap.pushCode(record->code, record->codeLength); } /* Push this symbol to the data buffer */ - symbolsData.push_back(SymbolsHeap.size() + 1); // write down symbols size - for (auto t = SymbolsHeap.begin(); t != SymbolsHeap.end(); t++) { + symbolsData.push_back(symbolHeap.size() + 1); // write down symbols size + for (auto t = symbolHeap.begin(); t != symbolHeap.end(); t++) { symbolsData.push_back(*t); } } /* Write offsets block and their corresponding encoded symbols heap */ - if ( offsetsData.size() > 0 ) { - + if (offsetsData.size() > 0) { /* Add zero offset to finalize the block */ offsetsData.push_back(0x0000); diff --git a/tools/convsym/src/output/DEB2.cpp b/tools/convsym/src/output/DEB2.cpp index f2f141b1..0efd465d 100644 --- a/tools/convsym/src/output/DEB2.cpp +++ b/tools/convsym/src/output/DEB2.cpp @@ -4,6 +4,7 @@ * Output wrapper for the Debug Information format version 2.0 * * ------------------------------------------------------------ */ +#include #include #include #include @@ -27,13 +28,15 @@ struct Output__Deb2 : public OutputWrapper { * Main function that generates the output */ void parse( - std::multimap& SymbolList, + std::multimap& symbols, const char * fileName, uint32_t appendOffset = 0, uint32_t pointerOffset = 0, const char * opts = "", bool alignOnAppend = true ) { + assert(!symbols.empty()); + auto output = OutputWrapper::setupOutput( fileName, appendOffset, pointerOffset, alignOnAppend ); /* Parse options from "-inopt" agrument's value */ @@ -50,7 +53,7 @@ struct Output__Deb2 : public OutputWrapper { output->writeBEWord(0xDEB2); /* Allocate space for blocks offsets table */ - auto lastSymbolPtr = SymbolList.rbegin(); + auto lastSymbolPtr = symbols.rbegin(); uint16_t lastBlock = (lastSymbolPtr->first) >> 16; if (lastBlock > 0xFF) { // blocks index table is limited to $100 entries (which is enough to cover all the 24-bit addressable space) @@ -73,11 +76,11 @@ struct Output__Deb2 : public OutputWrapper { /* Generate table of character frequencies based on symbol names */ uint32_t freqTable[0x100] = { 0 }; - for ( auto& Symbol : SymbolList ) { - for ( auto& Character : Symbol.second ) { - freqTable[ (int)Character ]++; + for (auto& symbol : symbols) { + for (auto& character : symbol.second) { + freqTable[(int)character]++; } - freqTable[ 0x00 ]++; // include null-terminator + freqTable[0x00]++; // include null-terminator // TODOh: Guess whether NULL will be appended to the string of specified length } @@ -104,16 +107,16 @@ struct Output__Deb2 : public OutputWrapper { /* ------------------------------------- */ { - IO::Log( IO::debug, "Generating symbol data blocks..."); + IO::Log(IO::debug, "Generating symbol data blocks..."); - auto symbolPtr = SymbolList.begin(); + auto symbolPtr = symbols.begin(); struct SymbolRecord { uint16_t offset; uint16_t symbolDataPtr; }; /* For 64kb block within symbols range */ - for ( uint16_t block = 0x00; block <= lastBlock; block++ ) { + for (uint16_t block = 0x00; block <= lastBlock; block++) { /* Align block on even address */ - if ( output->getCurrentOffset() & 1 ) { - output->writeByte( 0x00 ); + if (output->getCurrentOffset() & 1) { + output->writeByte(0x00); } uint32_t loc_Block = output->getCurrentOffset(); // remember offset, where this block starts ... @@ -122,16 +125,20 @@ struct Output__Deb2 : public OutputWrapper { std::vector offsetsData; /* For every symbol within the block ... */ - for ( ; (symbolPtr->first>>16) == block && (symbolPtr != SymbolList.cend()); ++symbolPtr ) { + for (; (symbolPtr->first>>16) <= block && (symbolPtr != symbols.cend()); ++symbolPtr) { + if ((symbolPtr->first>>16) < block) { + continue; + } /* * For records with the same offsets, fetch only the last or the first processed symbol, * depending "favor last labels" option ... */ - if ( (optFavorLastLabels && std::next(symbolPtr) != SymbolList.end() + if ((optFavorLastLabels && std::next(symbolPtr) != symbols.end() && std::next(symbolPtr)->first == symbolPtr->first) || - (!optFavorLastLabels && symbolPtr != SymbolList.begin() - && std::prev(symbolPtr)->first == symbolPtr->first)) { + (!optFavorLastLabels && symbolPtr != symbols.begin() + && std::prev(symbolPtr)->first == symbolPtr->first) + ) { continue; }