This shows you the differences between two versions of the page.
— |
blog:pushbx:2022:0424_ldebug_expression_evaluator_learns_to_use_types_poorly [2022-04-24 14:12:06 +0200 Apr Sun] (current) ecm created |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== lDebug expression evaluator learns to use types (poorly) ====== | ||
+ | |||
+ | One week ago I finally had to confront | ||
+ | a long-standing defect in lDebug' | ||
+ | expression evaluator: It didn't support | ||
+ | types. I found out because all numbers | ||
+ | that were " | ||
+ | (ie values that are >= '' | ||
+ | were accepted for narrower callers, | ||
+ | that is, '' | ||
+ | These functions are called for things | ||
+ | such as offsets, E/S/F command strings, | ||
+ | and permanent breakpoint counters. | ||
+ | |||
+ | ===== ===== | ||
+ | |||
+ | I didn't notice for a long time | ||
+ | because I only used fitting values | ||
+ | or -1, the latter which happened to | ||
+ | be allowed through because of a bug. | ||
+ | The bug was that the '' | ||
+ | ended up with a count of 32 bits for | ||
+ | large numbers, yet [[https:// | ||
+ | the least **five** bits | ||
+ | as holding the count. | ||
+ | Therefore a count of 32 overflowed to 0 and | ||
+ | the callers that did check the count | ||
+ | (only [[https:// | ||
+ | at the time) never detected that these | ||
+ | large numbers were outside their limits. | ||
+ | |||
+ | Now [[https:// | ||
+ | was to use six bits to return the count. | ||
+ | But that broke the acceptance of negative | ||
+ | values such as -1. So | ||
+ | [[https:// | ||
+ | was to treat all numbers as signed. | ||
+ | As marked in the changeset description | ||
+ | we considered this a magic hack though. | ||
+ | |||
+ | [[https:// | ||
+ | came along briefly after the magic: | ||
+ | Almost complete support for types. | ||
+ | In particular, the unary minus operator | ||
+ | sets its value' | ||
+ | allowing literals prefixed by a | ||
+ | unary minus to be handled as signed | ||
+ | numbers by the significant bits counting. | ||
+ | Explicit type keywords such as '' | ||
+ | (signed word) versus '' | ||
+ | also allow to specify signedness. | ||
+ | Other than that, binary operators | ||
+ | have a complicated relationship to types. | ||
+ | As noted in the changeset message | ||
+ | we may revisit some of those later on. | ||
+ | |||
+ | Eventually [[https:// | ||
+ | had to be dropped because it passed | ||
+ | a literal of '' | ||
+ | permanent breakpoint' | ||
+ | (Literals without any type keyword or | ||
+ | operator are considered unsigned | ||
+ | by default, like most all expression terms, | ||
+ | except for parens-surrounded subexpressions.) | ||
+ | This is now considered broken and | ||
+ | unsupported. Note that minus one is | ||
+ | still allowed, as desired. | ||
+ | |||
+ | The type support soon was used to | ||
+ | [[https:// | ||
+ | we'd long desired: | ||
+ | specifying a '' | ||
+ | allows to use a 32-bit expression | ||
+ | as a 16:16 far pointer. | ||
+ | This is most useful with compound | ||
+ | variables like '' | ||
+ | or with a memory dword that we want to | ||
+ | read as a far pointer without specifying | ||
+ | the memory address twice, eg '' | ||
+ | to return from a 16-bit far function | ||
+ | or interrupt handler. (This previously | ||
+ | required a command like | ||
+ | '' | ||
+ | Besides, '' | ||
+ | the check for 16 significant bits. | ||
+ | |||
+ | Another change that came along | ||
+ | was checking the significant bit widths | ||
+ | for [[https:// | ||
+ | that write to a variable or memory location. | ||
+ | The need for this check had been noted | ||
+ | [[https:// | ||
+ | that originated in an early revision, in 2010 October. | ||
+ | This had the knock-on effect of failing a | ||
+ | test that used a command | ||
+ | reading '' | ||
+ | to bitwise invert a 16-bit register. | ||
+ | We [[https:// | ||
+ | by inserting a '' | ||
+ | |||
+ | Writing of old revisions, the lack of | ||
+ | types in the expression evaluator | ||
+ | goes back all the way to | ||
+ | [[https:// | ||
+ | of lDebug in 2010 (still called | ||
+ | NDebug at the time). | ||
+ | |||
+ | |||
+ | {{tag> | ||
+ | |||
+ | |||
+ | ~~DISCUSSION~~ | ||