Yesterday I revisited a nasty problem that occurs on Windows 64bit versions. I ran into that when I upgraded to Windows 7, but it seems it affects older 64bit editions of Windows as well.

After installing D2009 on a clean Win7 machine I was happy to see that Windows 7 really is what Vista should have been. It works snappy and has a lot of productivity features. But then when I started compiling and debugging a couple of my existing Delphi applications I experienced Debugger crashes almost everytime when I terminated an application.

image


Unfortunately no matter if you press “Yes” or “No” on that screen – you have to restart the whole Delphi IDE – which basically makes debugging impossible. In some (actually many) cases you even have to terminate Delphi using Windows TaskManager. I tried all of the compatibility settings Win7 offers, as well as running Delphi as Administrator – but no luck.

Some research on Google, QC and RAID showed that similar exceptions were reported with older Delphi versions, but apparently only on 64bit Windows editions. As the message already suggests, the problem appears to be an invalid call to a SetThreadContext API call. Some tests showed that you can easily reproduce this issue once you have more that just a single thread in your Delphi application. As you might know, I am doing quite a lot of Web application server development – which by nature create many threads…

I created a RAID entry for that (actually an existing one was updated with detailed reproduction steps – iirc) and joined a discussion thread on that topic to see if others are reporting that too. Because of time constraints I did not revisit that issue over the last couple of weeks, but yesterday when I was talking to Daniel Magin, we together found a solution someone had posted on a German Forum a few weeks ago. The original idea is from an MS TechNet posting though (credits go to a guy called Xelax Ax).

He posted a workaround that basically disables the check for a possible error returned by SetThreadContext, i.e. the debugger ignores the error and does not crash because of the Assert that checks fro no error returned. As Andreas Hausladen already correctly mentioned, this is really just kind of a weak workaround, because the debugger might misbehave after that and we just do not know why SetThreadContext fails at all. The point is though that with this fix I can work effectively again with D2009 on Win7/64bit and as this error only happens when the debugger is about to shout down anyway, so the danger of unwanted side effects is not too high imho.

Be careful! No waranties! I am not responsible for lost files etc.! Back up first!

Workaround steps:

  1. Close Delphi
  2. Locate bordbk120N.dll (C:\Program Files (x86)\CodeGear\RAD Studio\6.0\bin)
  3. Make a backup copy
  4. Check step 3
  5. Open bordbk120N.dll in a Hex editor (UltraEdit works fine)
  6. Search for “01 00 48 74 47 80 3D
  7. Make sure this is found once only
  8. Replace “74” with  “EB
  9. Save
  10. Restart Delphi. Error should be gone.

This might work on older Delphi versions as well, but I did not test that yet.

Update 1

I talked to some CodeGear Q&A guy and he tested their current internal Weaver build under the conditions where D2009 fails. The good news is that the error seems to be gone there – so the next Delphi Version will probably be good. For those who want to get started now: please see Update 2 below.

Update 2

LordByte sent me his automatic patch tool for Delphi 2007 and Delphi 2009. Just click “Apply patch” and you are done.

image

Get the patcher here: Delphi_2007_2009_WOW64_Debugger_Fix.zip (169 KB)

Note: Provided as is for free. Use at your own risk.

  • Michael

    So who is in charge of this to fix this annoying bug? I don't think it's Microsoft actually – so I guess CG is responsible to hot fix this in their latest flagship D2009 (and hopefully not in an upcoming version)

    Michael

  • http://www.monien.net/blog Olaf Monien

    CG will certainly say, that D2009 was released before Win7 and Win7 is not even officially released yet.
    I talked to some Q&A guy of CodeGear, he checked that error on their current internal build, and the error does not seem to be reproducible anymore. So chance are that we might get an update somewhen.

    One question here is certainly: what will be released earlier? Delphi next version (Weaver) or Win7?

  • http://dmagin.wordpress.com/2009/07/21/windows-7-64bit-delphi-debugger-fix-workaround/ Windows 7 64bit Delphi Debugger Fix / Workaround « Daniel Magin’s Weblog

    [...] the blog site from my friend Olaf Monien you can find now a automatic path tool. it makes the changes for foru with one click. Possibly [...]

  • remko

    Interesting issue. If we look into the pseudo code of this function:
    *(_DWORD *)(a1 + 3548) = 65551;
    if ( SetThreadContext(*(HANDLE *)(v1 + 684), (const CONTEXT *)(a1 + 3548)) != 1 )
    {
    if ( byte_455BAC )
    {
    v8 = GetLastError();
    v9 = (*(int (__cdecl **)(int))(*(_DWORD *)v1 + 132))(v1);
    sub_401B08(“setContext osTId 0x%x failed %d”, v9, v8);
    }
    if ( “SetThreadContext failed” )
    sub_40C6AC(“(!”SetThreadContext failed”)”, “..\win32src\thread32.cpp”, 434);
    }

    We can see that the Context flag is set to 65551 and if we look into the comments in the header file (winnt.h):
    #define CONTEXT_AMD64 0×100000
    #define CONTEXT_i386 0×00010000

    #define CONTEXT_SEGMENTS (CONTEXT_i386 | 0x00000004L) // DS, ES, FS, GS

    so all other flags are combines with either CONTEXT_AMD64 or CONTEXT_i386. It might be worth trying to patch this flag to the corresponding value for AMD64. If someone wants to try:
    .text:0043C7F5 C7 83 DC 0D 00 00 0F 00 01 00 mov dword ptr [ebx+0DDCh], 1000Fh

  • Name

    Thanks a million, dude. From your information I have a created a fully automatic patcher. The patcher has been used by 8 colleagues (so far) of mine, and they all report success .. no more assertion errors.

  • http://www.monien.net/blog Olaf Monien

    Whohoo! Do you mind sharing that patcher? If you don't have a webspace, I can easily host it here on the blog.

  • http://www.monien.net/blog Olaf Monien

    Thanks for your comment – esp. for the highly interesting link about GetThreadConbtext on WOW64

  • claudio68

    Hi Olaf's

    GREAT! GREAT! GREAT!!!

    Thank you very muche for this solution!!

    best Regards

  • Name

    I dont mind at all.

    Please instruct me where to upload (FTP?), or give me an email adress I can send the attachment to :-)

    Best regards

  • http://www.monien.net/blog Olaf Monien

    Please send via e-mail to olaf (at) monien (dot) net

    My mailbox has no size limit.

    Regards,
    Olaf

  • Michael

    Regarding your last question: In this case I would prefer Win 7 to be released earlier. Let's see if the Delphi community has got enough power to 'force' CG to release a hot fix for this issue.

    Michael

  • Name

    Mail on its way.
    Hope it will solve the problem for all you guys.

    Best regards
    LordByte

  • http://www.monien.net/blog Olaf Monien

    Great – thanks! I have posted a link to the patcher under “Update 2″ above.

  • Name

    Will even update it for other versions of Delphi,
    if anyone so desire. You must provide the
    native BORDBGxxxN.dll for inspection, and the
    BDS-basekey in the HKEY_CURRENT_USER registry-hive.

    Anyway, I hope it works for all of you.

    Best regards
    Lordbyte

  • remko

    I don't have an x64 os so I can't try but you can also try to make the following change:
    C7 83 DC 0D 00 00 0F 00 01 00 to C7 83 DC 0D 00 00 15 00 01 00

    It changes the Context flag from 65551 (CONTEXT_FULL or CONTEXT_FLOATING_POINT) to 65557 (CONTEXT_ALL)

  • Name

    Have tested it .. Changed 0x0F to 0×15

    Additional assertion errors not seen before occured.

  • zvyagaaa

    Thanks a lot for your solution :) With Love From Siberia

  • John

    Sweet dude, the automatic patch tool works like a charm, I can finally debug again!

  • Carl Clark

    Hoo Haa!
    Thanks a million Olaf and LordByte (Patcher worked on my Delphi 2007).

  • http://www.turbu-rpg.com/ Mason Wheeler

    Not sure how much this affects older versions of Windows. I've been running Delphi 2009 under Vista 64 for almost a year now and never seen this problem once, even in multi-threaded apps.

  • OnasJ

    thx alot for this solution!

  • nokfarang002
  • Ron Sharp

    Thanks! That did the trick with Delphi 2009 and Windows 7 for me (after I remembered to run it as an admin). There still seems to be a delay between closing the app and control returning to the IDE, but that's preferable to having to restart Delphi.

    It would be nice if there was an official patch for this, short of Delphi 2010, since it wasn't that long ago that I upgraded to 2009.

  • CRM455

    Thanks guys,
    This saved me a lot of time trying to figure out what is going on.
    Patch program worked great on D2007.
    :)
    Chris

  • Davit

    THANK YOU VERY MUCH

  • philipljackson

    Thanks guys,
    I would never have been able to solve this one myself
    Patch program worked great on D2007.

  • piranha

    Thanks dude!

  • manishfusion

    Hi, very interesting blog. Nice work!

    Hot deals

  • martin123

    Hi, it’s a so nice and good site ever. It’s a really great and fantastic post here in this site. Thank you for the sharing of your ideas and information to all of us.mortgages.Thanks Regard.

  • http://www.tsgames.de/ Torsten

    Thanks guys! This really worked for me, great.

  • alfchristophersen

    What about BDS 2006 which I must have running on Windows 7 in a few weeks from now when my boss, University of Oslo is going to abandon completely XP and Vista and all 32-bits computers. Just installing 64 bits Windows 7 in all computers.

    Sounds like a “suicide” to me for those of us needed to support also old 2006 code with Ansi support for a long time still because of amount of code to change in order not to break binary streams.

  • http://www.monien.net/blog Olaf Monien

    Honestly, I didn't try BDS2006 on Windows 7. Maybe you should setup virtual machines (with XP) to run BDS2006.

    Regards / Grüße,
    Olaf Monien
    ——————————————
    EDV-Beratung Monien

    Embarcadero Technology Partner
    Delphi Experts Chairman
    http://www.delphiexperts.net
    http://www.monien.net

    Am 03.01.2010 um 18:28 schrieb Disqus:

  • Name

    Thanks alot for this! :) Works for me too. (W7 x64)

  • Name

    Hi!

    Just a quick verification: Can someone please verify that this problem does NOT occur anymore in Delphi 2010?

    Thanks!

  • http://www.monien.net/blog Olaf Monien

    I have not seen that problem on my D2010/Win64 bit installation so far. IIRC it was marked as fixed in RAID.

    Regards / Grüße,
    Olaf Monien
    ——————————————
    EDV-Beratung Monien

    Embarcadero Technology Partner
    Delphi Experts Chairman
    http://www.delphiexperts.net
    http://www.monien.net

    Am 12.01.2010 um 09:34 schrieb Disqus:

  • Mike Potter

    Thanks VERY much for supplying this patch. Worked great for me with Delphi 2007 on Windows 7 to fix this annoying problem.

  • http://gisnap.com gisnap

    Thanks for sharing, i love this post

    http://currnews.com/
    currnews.com
    Very much live news

  • Juanma

    Thank you very much.
    I reinstall my C++Builder 2007 in a W7 x64 an get this error (not always, but frecuently).
    I had edited bordbk120N.dll and now work ok. Great.

    Best regards
    Juan Manuel Marin

  • andrei

    Thanks for the patch. it worked.

  • karlgeppert

    Thanks for that – takes the stress back out of my day. The auto-patcher worked beautifully once I woke up enough to remember to run it as admin on win7.

  • pcunite

    I have CB2007 installed on Win7 x64 and I don't have the bordbk120N.dll file but I do have bordbk105N.dll. Any ideas as I have the same error?

  • pcunite

    Solution, I edited it the same as bordbk120N.dll would need and it worked.

  • http://www.monien.net/blog Olaf Monien

    Your dll is definitely a different Version. I didn't touch C Builder
    for while, so I don't have a sugestion right now. Sorry


    Grüße / Regards,
    Olaf Monien

    Sent via iPhone

    Am 12.03.2010 um 10:12 schrieb “Disqus” <
    >:

  • pcunite

    Well I can confirm after using it all day that it works. If it help my CB2007 version is:
    CodeGear™ C++Builder® 2007 R2 Version 11.0.2902.10471
    Installed Updates:
    December 2007 Update
    May08 Help Update

  • Marcello Grec

    Hi Olaf.
    Thank you!

  • Michael

    Thank you for the interesting article and LordByte for the patcher.
    This bug was really annoying…

  • http://blog.kp.ru/users/aliferster/ AliFerster

    Great THANKS!!!!!!!!!!!++++++++

  • Ryan

    Thank you for the link to the patcher, and thanks to LordByte for the patch itself! I've been dealing with the issue for the past few weeks and finally thought I'd search for a fix. Great patcher, thanks!

  • ricardosartorato

    Man you rocks.

    The “update 2″ works perfectly.

    Thanks very much your attention to share this.

    Best Regards…

  • donsergio

    Great, thanks man.

  • Tiziano

    Update 2 – Delphi_2007_2009_WOW64_Debugger_Fix.zip funziona correttamente ed elimina il problema.
    Grazie !

  • http://www.monien.net/blog Olaf Monien

    I assume this means it worked for you…

    Grüße / Regards,
    Olaf Monien

    Sent from my iPad

    Am 25.05.2010 um 18:45 schrieb “Disqus” <>:

  • Guus

    Hi,

    This does not fix debugging a Delphi.NET project (dll) ?

    Kind regards,
    Guus

  • http://www.monien.net/blog Olaf Monien

    Delphi 2009 does note have a .NET personality anymore.

    Grüße / Regards,
    Olaf Monien

    Sent from my iPad

    Am 08.06.2010 um 11:09 schrieb “Disqus” <>:

  • Guus

    Ok, I mean: Delphi 2007.NET.

  • http://www.monien.net/blog Olaf Monien

    The .Net Debugger is a separate assembly/dll in D2007, which we didn't figure out a patch for. As I moved my Delphi.net stuff to Prism anyway, I didn't experience any debugger issues …

    Grüße / Regards,
    Olaf Monien

    Sent from my iPad

    Am 08.06.2010 um 20:38 schrieb “Disqus” <>:

  • Max Vikulov

    Thank you alot! It works… :)

  • Chisi

    Thanks, couldn't get the patch to work, but the workaround steps worked great!

  • http://www.discount-louis-vuitton.com louis vuitton for sale

    Well , the view of the passage is totally correct ,your details is really reasonable and you guy give us new balance 1300 valuable informative post, I totally agree the standpoint of upstairs. I often surfing on this forum when I m free and I find there are so much good information we can learn in this forum!

  • http://profiles.yahoo.com/u/XBF24O7BAII7QPXQYGI7FTZQJE Ma. A

    This solution works for delphi 5? i have the same error

  • http://www.monien.net/blog Olaf Monien

    nope – this is D2009 and possibly D2007 only

    Regards / Grüße,
    Olaf Monien
    ——————————————
    http://www.developer-experts.net
    http://www.monien.net/blog

    Am 13.07.2010 um 16:01 schrieb Disqus:

  • http://profiles.yahoo.com/u/XBF24O7BAII7QPXQYGI7FTZQJE Ma. A

    ok thank y'all, i have other question what to do fix this problem in delphi 5 with win xp?

  • guest

    Thank you!

  • Oussama Alrifai

    That is just great guys… many thanks… you did save my miserable life.

  • Ans

    Brillient !

    Worked for CodeGear C++ Buider 2007

  • Mikael Morvan

    Thank You :) )))))))) My beloved Delphi is back :)

  • Jvann

    Ah, thank you. Delphi 2007 on Windows 7 64 bit. Embarcadero should release a fix/update for this.

  • Evgeniy

    LordByte, thank you very much!!!! You are the Great Man!!!!!

  • http://socialsubmit.info social bookmarking service

    I talked to some CodeGear Q&A guy and he tested their current internal Weaver build under the conditions where D2009 fails. Some research on Google, QC and RAID showed that similar exceptions were reported with older Delphi versions.

  • MGPetryk

    Thank you!!!!!!

  • GuyS

    Worked like a charm! Thank you, sir.

  • http://bani.deocazie.info Bani Pe Net

    everything seems to crash in Win7

  • Feichg

    Thank you so much!

  • http://nicheprofitclassroom3review.com Niche Profit

    wow thank you so much for posting this..you have saved my poor head from many massive headaches….thanks again

  • http://www.reg-cleaner.org Best reg cleaner

    OMG, my laptop windows 7 runs very slow.

  • Thev

    WOW…. 10Q

  • Roman

    It is my great pleasure to visit your website and to enjoy your excellent post here. I like them very much. I can feel that you paid much attention to those articles, as all of them make sense and are very useful. Thanks so much for sharing.

    _________________________
    SEO Armenia

  • Jwsandker

    Tried it, but D2009 hangs as soon as I hit F9 key. The patch didn’t work for me?
    Anyone a suggestion? I have new netbook Dell, W7, 64 bit

  • http://www.best-registrycleaner.net registrycleaner

    Worked great for me with Delphi 2007 on Windows 7 to fix this annoying problem.

  • bill[gr]

    Thank you very much both Author and Coder of the patch.

  • http://www.k9stud.com Puppies For Sale

    Thanks, couldn’t get the patch to work, but the workaround steps worked great!

  • Roy

    Thank you, danke schoen, heel erg bedankt!

  • CL

    Ща проверю )

  • Khalid

    WooooooooooooooooooooooooooW, Thank you LordByte so much
    You are my Man

  • http://www.swingset.com Swing Sets

    I like them very much. I can feel that you paid much attention to those articles, as all of them make sense and are very useful.

  • http://www.winlottory.com/ Win Lotto Tips

    Will you be selling iMacs at the store, and when will this open?

  • http://www.healthcompedium.com hecatom

    Delphi sucks.

  • Kb

    Thanks!

  • Fireton

    That’s cool! Thanx a lot!

  • http://security-wire.com/11/how-to-remove-spyware-protection-2010-rogue-anti-spyware.html remove spyware protection 2010

    Your article is really helpful!

  • Alexander Gofen

    ear Mr. Olaf Monien,

    Thank you very much for posting this solution, which does work OK for me.

    What seems surprising and even incredible is that a methodological inconsistency of Delphi 2009 vs. Windows-7 may be fixed by changing just one byte in the dll.

    I did the whole project via a small program in Delphi which reads the dll as a file of bytes, examines it, edits that particular byte, and saves the file replacing the (copy) of the dll.

    Thanks again!

    Alexander Gofen

  • Jbdemonte

    Great !!

    Real thanks ! it was a real boring problem !

    jb

  • http://security-wire.com/01/how-to-remove-palladium-antivirus-rogue-anti-spyware.html remove Palladium Antivirus

    Your article is really helpful!

  • Snokez

    Thanks a lot! Works perfectly on a Win7-64/D2009 system. Keep up the good work! ;-)

  • http://www.squidoo.com/computer-lottery-software Lottery Software

    This is great.
    Thank you so much.

  • Chh31

    Olaf (and LordByte) thank you very much for that info – Works great!!

  • Fruitbat

    Heartfelt thanks for this page and for the patch tool – which was instantly efficacious. Was about to despair of being able to use Delphi 2007 on Win 7 x64, but now all is lovely.

  • http://blogtext.org/lottosoftware54/article/381125.html Lottery Software

    Thank you for sharing this information..

  • http://www.facebook.com/people/Ömer-Kaya/1834561474 Ömer Kaya

    Thanks. Good job. :)

  • Yagil

    Great job!
    I know I am late, yet
    Straight forward solution, simply great!
    The workaround works like charm.
    I always wonder how you guys come up with such solutions, I mean even if you know the relevant DLL, to dig 1 HEX out of thousands…

  • Yagil

    Great job!
    I know I am late, yet
    Straight forward solution, simply great!
    The workaround works like charm.
    I always wonder how you guys come up with such solutions, I mean even if you know the relevant DLL, to dig 1 HEX out of thousands…

  • http://www.monien.net/blog Olaf Monien

    We tried all combinations ;)

    Grüße / Regards,
    Olaf Monien

    Sent from my iPad

  • http://twitter.com/hoitjuh55 Dennis Dekker

    Thanks a lot, Olaf and LordByte! Patcher worked great for me.

  • Jmcintyrelaw

    Thanks for your update.

  • http://www.bitcell.info DarkByte

    Thanks guys, the patcher worked OK on a Windows 7 x64 / Delphi 2009 installation.

  • Roland

    Thanks guys!

  • Daryl

    Wow!! I thought I would never get this fixed and it was such a painful problem. The patch worked great for me for Delphi 2009 in Windows 7 and I am very happy and grateful! Thanks so much.

  • Jimabradford

    Thanks Olaf !

  • Shahram

    hi
    After it I Get “External Exception EEFFACE”
    What’s This?
    What Can I Do?
    In Delphi 2007

  • http://www.monien.net/blog Olaf Monien

    As nobody else reported an error yet, I assume that your Delphi 2007 has been patched/modified by some other means. Maybe try re-installing first …

    Regards / Grüße,
    Olaf Monien
    CEO
    ——————————————
    Developer Experts, LLC
    http://www.developer-experts.net
    http://www.monien.net/blog

    Office USA
    10600 Chevrolet Way #211
    Estero, FL 33928
    Fon: +1 (239) 494 5049

    Office Germany
    Gerhart-Hauptmann-Ring 134
    60439 Frankfurt am Main
    Fon: +49 (69) 175 548 150

    Am 13.06.2011 um 08:41 schrieb Disqus:

  • Omer

    I’ve just tried that fix and it’s working.I’m posting this on Sep 1, 2011.
    There are some variations, though:
    The DLL name is “bordbk105N.dll”
    I’ve used the HxD editor (http://mh-nexus.de/en/hxd/).
    Omer.

  • Alikhani

    Great job!

  • Sue

    Thanks for this.  A potential problem has been sorted very quickly.

  • G. Fernando Castro Gro.

    Hi

    the patch is not working for me, so please, if anyone knows the string I have to change in the file : bordbk105N.dll

    I applreciate a lot your help.

    Best regards

    Fernando

  • G. Fernando Castro Gro.

    Hi

    the patch is not working for me, so please, if anyone knows the string I have to change in the file : bordbk105N.dll

    I applreciate a lot your help.

    Best regards

    Fernando

  • http://www.monien.net/blog Olaf Monien

    Please make sure you have all updates installed. Also remember this patch is for Delphi 2009 only.
    Grüße / Regards,
    Olaf Monien

    Sent from my iPad

  • G. Fernando Castro Gro.

    Solved, thanks. I executed the patch as Admin and the file was patched succesfully. 

    Thanks and best regards

    Fernando

  • Jlevy308

    when statring delphi for the first time and it doesnt work it will say file in :C/programefiles/delphi/bin/ delphi . thats the exe. file . just add .dro’ to the name and it will work…(not 100% accurate naming but try it)

  • Volpino40

    grazie!

  • Arto

    Hi,

    I had the same problem and I run LordByteses ..Fix.zip. And now the sun is shining again so
    thank you all vary mutch.

    -ArtZi

  • Belal Al-Hamed

    Thanks a lot

  • Yojo

    Just saved me a lot of headache.

  • Remco

    Great patch…  ;)
    Thanks!

  • http://www.webhostings.in/ web hosting companies

    I found some really interesting stuff in your blog especially this discussion. Keep up the good work.

  • http://pulse.yahoo.com/_4LFPBDXNOT7AVB3VVLTYSAWBJA CAMILO

    Excelente, la operación de edición de la dll sirve también para delphi 2007 con windows 7 de 64. En este caso la dll es:  bordbk105N.dll

  • BrianD

    The patch program won’t open the file, even though it is searching the correct path.  The program asks is Delphi opened.  It’s not.  I’ve changed the bordbk file from read only, but that doesn’t work.  Any suggestions?

  • Timon Com

    I Have manually patched this file to avoid this error in Delphi 2007:

    C:Program Files (x86)RADStudio_2007_LiteBinbordbk105N.dll

    and its working!! Thank you Olaf!

    (The patch from LordByte did not work for me )

      which Delphi version du you use? Try to find the “bordbk105N.dll” and try the workaround steps with UltraEdit without the patch

  • bigman

    I ran the patch as administrator otherwise it gave me an error asking if Delphi was running…

blog comments powered by Disqus
CodeGear Technology Partner