Monday, May 24, 2004

Hack #2: Fixing System.pas line numbers after D7.1 update

There has been some discussion in the newsgroups about the Delphi 7.1 update and the apparent mismatch between the patched System.dcu and the original System.pas source unit. Unfortunately, Borland did not include it in the original D7.1 patch, but I understand they are planning to include the correct version soon

. The problem occurs when you try to step into RTL code that resides in the System unit. For instance, fire up a new Console project (File | New | Other | Console Application - yeah, we D7'ers do envy you D8'ers the File | New | Customize... command) and add the following high-tech code:

program Project1; 

Writeln('Look - no hands, ma!');

Now enable the RTL/VCL units with debug info enabled by selecting Project | Options | Compiler | [X] Use Debug DCUs. Put the cursor on the Writeln line and press F4 to run to cursor (assuming you use the 'correct' keyboard bindings). Then press F7 to step into the code. With the D7.1 update applied you'll now find yourself at the end of the _LStrOfChar procedure inside System.pas. In other words, you're lost.

You'll also see that the blue dots signifying breakpointable code-lines are not aligned correctly with the actual source code. This is a typical sign of a mismatch between the source code and the actually compiled code. So until Borland gets the correct version of System.pas published in an updated update, we are stuck.

Or are we? Hackers like us don't like twiddling our thumbs, declaring defeat. If you look a little more closely at the mis-aligned blue dots and the wrongly positioned cursor in System.pas (it should have been down in Write0LString a few lines below), we can quickly determine how many lines we're off.

To get it right, we have to delete some lines - 8 lines, actually. But what should we delete?. If we scroll back to the top of the System.pas unit, we find some interesting, but less-than-useful comments about the GNU GPL license. As luck should have it, there are 8 lines in there. So, I delete them. And re-run the test application. Lo and behold, we now end up were we expect - in the Write0LString function! Great! A quick testing shows that other System routines now map to the correct line numbers too. Neat!

The conclusions are:

  • The original D7.0 System.pas included that extra 8 lines with GNU GPL info

  • The D7.1 compiled System.dcu was apparently compiled with a version of System.pas without that extra comment header

  • The D7.1 update did *not* include the updated System.pas

  • Apparently, no other line-number changing modifications were made to System.pas

And finally: This is only a short-term stop-gap measure until the official update with the correct System.pas is available from Borland. That file probably will contain other changes as well (otherwise System.dcu wouldn't have been updated in the first place).

Update: The System unit was updated due to a 1K buffer-size issue in LoadResString, see BDN article.


Anonymous said...

If you're putting my name in the list of Bloggers, Hallvard, it's "Chee Wee, Chua" or "Chua, Chee Wee". Otherwise, people might mistake one of the words as my name, as you may have found out elsewhere, where we hang out together. ;o)

Hallvard Vassbotn said...

OK - better now? :)

Fernando Madruga said...

I was finding it strange so many posts from you at once and so many about "old" versions of Delphi, then I looked at the top of this article: "Monday, May 24, 2004", which is odd as DelphiFeeds picked it up as "Thursday, 21. June 2007"...

This is no doubt related to your ongoing site changes and now that I know it, I'll pay more attention before commenting on very old articles! :)

(I was about to ask who on earth could still be worried about this after so many years, and when I saw the "they are planning", I though: Codegear is crazy wasting time on such old Delphi versions! Then I noticed the article's date!)

AviDen said...

You can even deal without deleting GPL header text (this is license infringement, after all) ;)

In Interface section, starting from line 1201, between _Halt0 and Mark function headers, is exact 8 empty lines. It seems that somebody incidentally inserted this boring linefeeds and thus made this problem.

Copyright © 2004-2007 by Hallvard Vassbotn