You Can Hack .NET Without Buying Visual Studio .NET
Pages: 1, 2
Cordbg.exe, the .NET Debugger
The .NET Framework SDK utilities include a debugger, and if you learn to
use it, your life as a .NET programmer will be much simpler. Let's use the
debugger (cordbg.exe) to examine this problem. First, start
the program under control of the debugger. You are greeted by the
(cordbg) prompt. The command run Hello.exe is
invoked automatically. Ignore that warning about mscorlib.dll; this just tells you that you can't debug the core library that contains many
important Framework Class Library types:
C:\home>cordbg Hello.exe
Microsoft (R) Common Language Runtime Test
Debugger Shell Version 1.0.3705.0
Copyright (C) Microsoft Corporation 1998-2001.
All rights reserved.
(cordbg) run Hello.exe
Process 1132/0x46c created.
Warning: couldn't load symbols for
c:\windows\microsoft.net\framework\v1.0.3705\mscorlib.dll
[thread 0xe10] Thread created.
007: string[] words = {"hello", "goodbye"};
(cordbg)
The first thing you'll do is set a breakpoint on the offending line with the
b command, and start the program with go. This
will stop execution in the first iteration of the loop and prompt you for
the next action:
007: string[] words = {"hello", "goodbye"};
(cordbg) b 11
Breakpoint #1 has bound to C:\home\Hello.exe.
#1 C:\home\Hello.cs:11 Main+0x1d(il) [active]
(cordbg) go
break at #1 C:\home\Hello.cs:11
Main+0x1d(il) [active]
011: Console.WriteLine(words[i]);
(cordbg)
At this point, the variable i should be set to zero, and
words[i] should be "hello". You can use the
print command to test this out:
(cordbg) print i
i=0x00000000
(cordbg) print words[0]
words[0]=(0x00c41844) "hello"
You can repeat this for the next iteration of the loop:
(cordbg) go
hello
break at #1 C:\home\Hello.cs:11
Main+0x1d(il) [active]
011: Console.WriteLine(words[i]);
(cordbg) print i
i=0x00000001
(cordbg) print words[1]
words[1]=(0x00c41860) "goodbye"
|
Related Reading C# Essentials |
Since there are two elements in the array, that should have been the last
iteration of the loop, right? But when you type go for a
third time, the program enters the body of the loop again:
(cordbg) go
goodbye
break at #1 C:\home\Hello.cs:11
Main+0x1d(il) [active]
011: Console.WriteLine(words[i]);
And what's worse, the current value of i is outside the
boundaries of the array (the array goes from 0 to 1):
(cordbg) print i
i=0x00000002
(cordbg) print words
words=(0x00c41880) array with dims=[2]
words[0] = (0x00c41844) "hello"
words[1] = (0x00c41860) "goodbye"
Use the show command to list five lines before and five lines
after the current line of code:
(cordbg) show
006: // create a list of strings
007: string[] words = {"hello", "goodbye"};
008: // iterate over the list
009: for (int i = 0; i <= words.Length; i++)
010: {
011:* Console.WriteLine(words[i]);
012: }
013: }
014: }
Take a look at line 9, where the loop is
controlled. It seems that I've introduced an off-by-one error by using
<= instead of <. Problem solved! Quit the
debugger with the quit command and open up your text editor
again to correct this error. The following example shows the corrected
program:
using System;
public class Hello
{
public static void Main()
{
// create a list of strings
string[] words = {"hello", "goodbye"};
// iterate over the list
for (int i = 0; i < words.Length; i++)
{
Console.WriteLine(words[i]);
}
}
}
And here is the output of running the program--no error this time!
C:\home>Hello
hello
goodbye
A Few Good Text Editors
Notepad is useful, but it doesn't have a huge set of features. For some people, this is just right; others may need something more featureful. Here is a list of C# editors I have experimented with:
- VIM (Vi IMproved)
- VIM is a
vi-compatible editor with many extra features. Grab csharp.vim to get C# syntax support. - GNU Emacs for Windows
- GNU Emacs is an editor favored by many programmers for its completeness and extensibility. You can find a C# syntax mode for Emacs here.
- jEdit
- jEdit is a Java editor written in Java that has support for C# syntax.
- SharpDevelop
- SharpDevelop is a free C# and VB .NET editor that's quite featureful and popular. It's completely written in C#, released under the GNU GPL, and offers features typical of an integrated development environment (IDE).
For more C# editors, see csharpindex.com's list of text editors.
Other C# Compilers
If you're not using a Windows platform but you'd still like to play around with C#, check out Mono or dotGNU, two projects that provide ECMA-compliant C# compilers and partial implementations of the .NET Framework Class Library. At the time of this writing, the C# compilers are still in their early stages, but a determined user shouldn't have any trouble using the compilers to develop and test simple C# programs. Also, Microsoft has announced a shared-source implementation of .NET that will include a C# compiler.
Brian Jepson is an O'Reilly editor, programmer, and co-author of Mac OS X Panther for Unix Geeks and Learning Unix for Mac OS X Panther. He's also a volunteer system administrator and all-around geek for AS220, a non-profit arts center in Providence, Rhode Island. AS220 gives Rhode Island artists uncensored and unjuried forums for their work. These forums include galleries, performance space, and publications. Brian sees to it that technology, especially free software, supports that mission. You can follow Brian's blog here.
O'Reilly & Associates recently released (January 2002) C# Essentials, 2nd Edition.
Sample Chapter 1, Introduction, is available free online.
You can also look at the Table of Contents, the Index, and the Full Description of the book.
For more information, or to order the book, click here.
Return to the .NET DevCenter.
Showing messages 1 through 12 of 12.
-
.NET SDK link broken
2004-08-29 03:20:44 miknight [Reply | View]
Instead try: http://www.microsoft.com/downloads/details.aspx?familyid=9b3a2ca6-3647-4070-9f41-a333c6b9181d&displaylang=en
-
Great Free C# IDE
2004-01-29 07:05:22 smartdevguy [Reply | View]
Hi Everyone,
I'm not sure if you're aware of this fact. Borland is offering a personal edition of their C# Builder for free. For those people intent on familiarising themselves with VS.NET without the cost, you can use Borland's cool emulation facility that is provided as standard with the product.
Link to product
http://www.borland.com/products/downloads/download_csharpbuilder.html
Hope this helps.
:-)
-
Another OpenSource C# IDE -Software Studio
2003-08-09 03:05:44 anonymous2 [Reply | View]
You can also find another open source IDE written in C# with large amount of language
'Software Studio'
Url : http://softwarestudio.smartcoding.org
-
Windows as an open developers desktop.
2002-10-01 17:25:54 anonymous2 [Reply | View]
Thank you for the article and the book(s). Given that most developers use some version of Windows as their desktop, I believe the community needs more articles / information on "command line", freely / cheaply available, tools that are available to perform Windows development. It seems to me that C# and the ability to develop in it without the investment in Visual Studio provide a great opportunity for an explosion of open source development on the de facto standard computing platform. Cheers!
-
OpenSource C# IDE
2002-04-10 07:10:12 semargofni [Reply | View]
There actually is an open source IDE available for C#, called SharpDevelop. It is still in Beta, but it beats editing in ordinary text editors. See http://sourceforge.net/projects/sharpdevelop/
-
.NET
2002-02-24 09:08:54 davidch [Reply | View]
1. so long as I can do it without Microsoft
and
2. so long as I dont have to commit to
any Microsoft dominated strategy
3. O'Reilly needs to drop its sponsership
by Microsoft and get back its integrity.
The technology no longer matters.
You wouldnt ask a hunger tiger the
directions to the nearest restaurant.
-
GUI Debugger
2002-02-14 18:37:00 Brian Jepson |
[Reply | View]
Jim Rafuse wrote in to remind me that:
the Framework SDK also comes with a GUI debugger. Look for DbgCLR.exe in the GuiDebug directory.
Thanks, Jim!
-
Ant support for .NET
2002-02-12 12:41:23 Marc Hedlund |
[Reply | View]
Ant's "Optional Tasks" jarfile contains several useful .NET tasks. They are documented here.
-
other free stuff for dotnet
2002-02-12 12:08:42 ianm74 [Reply | View]
You might also mention all the other free tools for C# and .Net development. Things like reflector for class browsing and lots of other goodies on gotdotnet
NUnit, NAnt and NDoc - the opensource tools for building and testing .Net code. -
other free stuff for dotnet
2002-02-14 18:35:56 Brian Jepson |
[Reply | View]






