• Stars
    star
    116
  • Rank 301,932 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created almost 11 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A command line client for the Mono soft debugger.

SDB: Mono Soft Debugger Client

SDB is a command line client for Mono's soft debugger, a cooperative debugger that is part of the Mono VM. It tries to be similar in command syntax to tools such as GDB and LLDB.

Building

Building and using SDB requires a basic POSIX-like environment, a Bash-like shell, the libedit library (or an API/ABI-compatible replacement), and an installed Mono framework.

First, clone the submodules:

$ git submodule update --init --recursive

To build, run:

$ make

If the build succeeds, you can install SDB with:

$ make install

(You may need to invoke it with sudo or some such command.)

You can also run SDB from within the build directory by appending it to PATH and invoking sdb-dev. This is mainly intended for development of SDB itself. An example:

$ export PATH=`pwd`/bin:$PATH
$ sdb-dev
Welcome to the Mono soft debugger (sdb 1.0.5058.39468)
Type 'help' for a list of commands or 'quit' to exit

(sdb)

You can run the SDB test suite with:

$ make check

(This requires an F# installation.)

The following variables can be set in your environment or on the make command line to affect the build:

  • CAT: Path to the cat POSIX utility.
  • CD: Path to the cd POSIX utility.
  • CHMOD: Path to the chmod POSIX utility.
  • CP: Path to the cp POSIX utility.
  • ECHO: Path to the echo POSIX utility.
  • FSHARPC: Which F# compiler executable to use.
  • FSHARPC_FLAGS: Flags to pass to the F# compiler.
  • FSHARPC_TEST_FLAGS: Flags to pass to the F# compiler for tests.
  • GENDARME: Which Gendarme executable to use (optional).
  • GENDARME_FLAGS: Flags to pass to Gendarme.
  • INSTALL: Path to the install POSIX utility.
  • MCS: Which C# compiler executable to use.
  • MCS_FLAGS: Flags to pass to the C# compiler.
  • MCS_TEST_FLAGS: Flags to pass to the C# compiler for tests.
  • MKDIR: Path to the mkdir POSIX utility.
  • NUGET: Which NuGet executable to use.
  • PKG_CONFIG: Path to the pkg-config utility.
  • RM: Path to the rm POSIX utility.
  • SED: Path to the sed POSIX utility.
  • TAR: Path to the tar POSIX utility.
  • MSBUILD: Which MSBuild executable to use.
  • MSBUILD_FLAGS: Flags to pass to MSBuild.

Additionally, MODE can be set to Debug (default) or Release to indicate the kind of build desired. PREFIX can be set to specify the path that the install and uninstall targets should operate within (defaults to /usr/local).

Finally, MONO_PREFIX and MONO_BINARY can be set to tell the check target which Mono executable should be used. See the description of RuntimePrefix and RuntimeExecutable further down for more information.

Usage

Running a program is simple:

$ cat test.cs
using System;
using System.Diagnostics;

static class Program
{
    static void Main()
    {
        var str = "Foo!";

        Foo(str);
    }

    static void Foo(string str)
    {
        Console.WriteLine(str);

        Bar();
    }

    static void Bar()
    {
        Debugger.Break();
    }
}
$ mcs -debug test.cs
$ sdb
Welcome to the Mono soft debugger (sdb 1.0.5060.15368)
Type 'help' for a list of commands or 'quit' to exit

(sdb) r test.exe
Inferior process '5234' ('test.exe') started
Foo!
Inferior process '5234' ('test.exe') suspended
#0 [0x00000001] Program.Bar at /home/alexrp/Projects/tests/cs/test.cs:22
        Debugger.Break();

A stack trace can be generated with bt:

(sdb) bt
#0 [0x00000001] Program.Bar at /home/alexrp/Projects/tests/cs/test.cs:22
        Debugger.Break();
#1 [0x00000007] Program.Foo at /home/alexrp/Projects/tests/cs/test.cs:17
        Bar();
#2 [0x00000008] Program.Main at /home/alexrp/Projects/tests/cs/test.cs:10
        Foo(str);

We can select a frame and inspect locals:

(sdb) f up
#1 [0x00000007] Program.Foo at /home/alexrp/Projects/tests/cs/test.cs:17
        Bar();
(sdb) p str
string it = "Foo!"

Or globals:

(sdb) p Environment.CommandLine
string it = "/home/alexrp/Projects/tests/cs/test.exe"

To continue execution, do:

(sdb) c
Inferior process '5234' ('test.exe') resumed
Inferior process '5234' ('test.exe') exited
(sdb)

We can then exit SDB:

(sdb) q
Bye

For more commands, consult help in SDB.

Options

SDB has a few command line options that are useful for automation. For the full list, issue sdb --help.

First of all, all non-option arguments passed to SDB are treated as commands that SDB will execute at startup. For instance:

$ sdb "run test.exe"

Or:

$ sdb "args --foo --bar baz" "run test.exe"

This starts SDB and immediately executes test.exe with the given arguments.

The first option is -f. This option specifies files that SDB should read commands from. These commands are executed before any commands specified as non-option arguments. This option is useful for longer command sequences that are easier to maintain in a separate file. Example:

$ cat cmds.txt
args --foo --bar baz
run test.exe
$ sdb -f cmds.txt

The second option is -b. This runs SDB in batch mode; that is, it will exit as soon as all commands have finished and no inferior process is running. This goes well with -f for running programs regularly under SDB.

Settings

One configuration element that you almost certainly need to alter is the RuntimePrefix string value. It is set to /usr by default, regardless of OS, which is probably not desirable everywhere. For example, on Windows, you will want to set it to something like C:\Program Files (x86)\Mono-3.0.10. Or if you have Mono in some other directory, you might set it to e.g. /opt/mono.

The RuntimeExecutable element is another way to specify which Mono executable to use. If RuntimePrefix is empty, then RuntimeExecutable is taken as the full path to the Mono executable. If both elements are non-empty, they are combined as Path.Combine(RuntimePrefix, "bin", RuntimeExecutable). This configuration element is useful for switching between mono32 and mono64 on OS X in particular.

You may want to set DisableColors to true if you don't want the fancy ANSI color codes that SDB emits.

Finally, three useful settings for debugging SDB itself exist: DebugLogging can be set to true to make SDB spew a bunch of diagnostic information. LogInternalErrors can be set to true to log any internal errors that are encountered in the Mono debugging libraries. LogRuntimeSpew can be set to true to log all messages from the Mono VM.

Paths

When configuration elements are changed with config set, SDB will store the configuration data in ~/.sdb.cfg. The content of the file is the .NET binary serialization of the Mono.Debugger.Client.Configuration class. This file is read on startup if it exists.

At startup, SDB will scan the ~/.sdb directory for plugin assemblies. It will attempt to load all command definitions.

Finally, SDB will read ~/.sdb.rc and execute any commands (one per line) from it. This is useful if you prefer to change your settings with commands that you write down manually, rather than storing the data in a binary file.

Environment

The SDB_COLORS variable can be set to disable to tell SDB to not use colors in output. Normally, SDB will not use colors if it detects that stdout has been redirected, that TERM is set to dumb (or not set at all), or if the DisableColors configuration element is true.

SDB_CFG can be set to a specific configuration file to use instead of the default ~/.sdb.cfg. If set to the empty string (i.e. SDB_CFG="" sdb), SDB will not load any configuration file at all, and changed configuration values will not be saved.

The SDB_PATH variable can be set to a list of additional directories that SDB will scan for plugin assemblies in. Each directory should be separated by a semicolon (Windows) or a colon (POSIX).

SDB_DEBUG can be set to enable to make SDB print diagnostic information while debugging. This may be useful to debug SDB itself.

Plugins

At the moment, SDB has one extension point which is the Mono.Debugger.Client.Command class and the related Mono.Debugger.Client.CommandAttribute class. A class implementing Command that is tagged with CommandAttribute will be instantiated at startup time and put into the root command list.

For SDB to find custom commands, they should be compiled into .dll assemblies and put in ~/.sdb (or some other directory specified in SDB_PATH). Plugin assemblies can also be loaded manually with the plugin command.

Here's an example of compiling and using a test plugin:

$ cat test.cs
using Mono.Debugger.Client;

[Command]
public sealed class MyCommand : Command
{
    public override string[] Names
    {
        get { return new[] { "mycmd" }; }
    }

    public override string Summary
    {
        get { return "Performs magic."; }
    }

    public override string Syntax
    {
        get { return "mycmd"; }
    }

    public override string Help
    {
        get { return "Some sort of detailed help text goes here."; }
    }

    public override void Process(string args)
    {
        Log.Info("Hello! I received: {0}", args);
    }
}
$ mcs -debug -t:library test.cs -r:$(dirname $(which sdb))/../lib/sdb/sdb.exe -out:$HOME/.sdb/test.dll
$ sdb
Welcome to the Mono soft debugger (sdb 1.0.5061.14716)
Type 'help' for a list of commands or 'quit' to exit

(sdb) h mycmd

  mycmd

Some sort of detailed help text goes here.

(sdb) mycmd foo bar baz
Hello! I received: foo bar baz

You can look at SDB's own command classes for some examples of things that you can do in your commands.

More Repositories

1

mono

Mono open source ECMA CLI, C# and .NET implementation.
C#
10,949
star
2

SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
C#
4,362
star
3

CppSharp

Tools and libraries to glue C/C++ APIs to high-level languages
C#
3,044
star
4

monodevelop

MonoDevelop is a cross platform .NET IDE
C#
2,821
star
5

xwt

A cross-platform UI toolkit for creating desktop applications with .NET and Mono
C#
1,368
star
6

taglib-sharp

Library for reading and writing metadata in media files
C#
1,270
star
7

Embeddinator-4000

Tools to turn .NET libraries into native libraries that can be consumed on Android, iOS, Mac, Linux and other platforms.
C#
758
star
8

VulkanSharp

Open source .NET binding for the Vulkan API
C#
536
star
9

CocosSharp

CocosSharp is a C# implementation of the Cocos2D and Cocos3D APIs that runs on any platform where MonoGame runs.
C#
495
star
10

monotouch-bindings

A collection of third party bindings for MonoTouch
C#
450
star
11

gtk-sharp

Gtk# is a Mono/.NET binding to the cross platform Gtk+ GUI toolkit and the foundation of most GUI apps built with Mono
C#
426
star
12

sharpen

Sharpen is an Eclipse plugin created by db4o that allows you to convert your Java project into c#
Java
380
star
13

t4

T4 text templating engine
C#
380
star
14

website

Mono's web site.
HTML
354
star
15

libgdiplus

C-based implementation of the GDI+ API
C
311
star
16

ngit

Automated jgit port to c#
C#
261
star
17

monomac

Bindings to create MacOS X applications with Mono.
C#
259
star
18

LineEditor

LineEditor is an interactive line editor for Command Line applications in .NET
C#
235
star
19

SkiaSharp.Extended

SkiaSharp is a cross-platform, comprehensive 2D graphics API for all .NET platforms. And, here is where you will find all sorts of extras that you can use with it.
C#
225
star
20

cxxi

C++ interop framework
C#
199
star
21

xsp

Mono's ASP.NET hosting server. This module includes an Apache Module, a FastCGI module that can be hooked to other web servers as well as a standalone server used for testing (similar to Microsoft's Cassini)
C#
193
star
22

roslyn

Roslyn Compiler - Tracks Mono Patches
C#
185
star
23

mono-addins

Mono.Addins is a generic framework for creating extensible applications, and for creating add-ins which extend those applications.
C#
165
star
24

docker

Docker images, for the Docker container system
Dockerfile
163
star
25

mono-tools

The mono-tools package contains a series of extra tools for Mono users.
C#
163
star
26

moon

Moonlight, an open source implementation of Silverlight for Unix systems
C#
159
star
27

mono-curses

Mono/.NET bindings to the Unix Curses as well as GUI framework for creating text applications with Curses
C#
138
star
28

winforms

Winforms samples for use with Mono's implementation of System.Windows.Forms
C#
133
star
29

aspnetwebstack

Mono branch of Microsoft's ASP.NET WebStack
C#
118
star
30

opentk

OpenTK is a set of bindings to OpenGL, OpenCL and OpenAL. This is not the main repository, just a temporary import to allow Mono developers to make changes to this module. Please do not contribute changes here, contribute them to the upstream maintainers at http://www.opentk.com
C#
115
star
31

cocos-sharp-samples

CocosSharp samples
C#
113
star
32

ikvm-fork

A fork of the original cvs based IKVM repository
C#
102
star
33

mono-basic

Visual Basic Compiler and Runtime
Visual Basic .NET
101
star
34

TsToCSharp

Emit C# strongly typed interface code from TypeScript definition files.
TypeScript
92
star
35

mono-upnp

UPNP binding for Mono/.NET
C#
85
star
36

debugger-libs

Debugger libraries
C#
78
star
37

dbus-sharp

DBus Sharp
C#
77
star
38

md-website

MonoDevelop WebSite
HTML
77
star
39

webkit-sharp

C#/CLI bindings to WebKit/Gtk+
C#
68
star
40

sysdrawing-coregraphics

System.Drawing implementation using CoreGraphics.
C#
67
star
41

api-doc-tools

.NET Reference API Toolchain
C#
67
star
42

maccore

MacCore contains the shared code between MonoTouch and MonoMac
C#
63
star
43

Mono.Zeroconf

Cross platform ZeroConf client that works with the underlying ZeroConf stack on the platform for Mono and .NET
C#
60
star
44

mwf-designer

Windows.Forms designer for Mono. Work in progress
C#
45
star
45

heap-shot

C#
42
star
46

cecil-old

ECMA CIL Manipulation Library
C#
42
star
47

tao

The Tao OpenGL, OpenAL, GLU, FreeGlut bindings for .NET and Mono
C#
38
star
48

monodroid-bindings

Mono for Android Jar Bindings
C#
36
star
49

mono.posix

POSIX/Unix interface for Mono, .NET and .NET Core. Provides functionality for managed code to access POSIX/Unix features not accessible via the BCL. This repository supersedes the older code in https://github.com/mono/mono
C#
35
star
50

entityframework

C#
33
star
51

monkeywrench

Continuous build system used by Mono and Moonlight.
C#
33
star
52

reference-assemblies

Binary reference assemblies
C#
32
star
53

linux-packaging-mono

Packaging metadata for mono-project.com packages
31
star
54

mod_mono

Apache module to host the XSP ASP.NET host
C
30
star
55

jurassic

Mono port of the Jurassic JS Engine (http://jurassic.codeplex.com/).
C#
27
star
56

mono-tls

New TLS implementation for Mono.
C#
27
star
57

bockbuild

Build & packaging system, responsible for the Mono project distribution for Mac
Python
26
star
58

xamarin-gtk-theme

C
25
star
59

linux-packaging-msbuild

C#
22
star
60

SkiaSharp-API-docs

SkiaSharp and HarfBuzzSharp API reference docs
PowerShell
22
star
61

uia2atk

Accessibility bridge between UIA and Gnome's ATK
C#
20
star
62

csvorbis

C#
20
star
63

mono-webbrowser

Browser backends for Mono.WebBrowser
C#
18
star
64

moma

Mono Migration Analyzer. A tool to scan compiled assemblies and determine their compatibility with Mono.
C#
18
star
65

olive

Olive is an incubation module used to host new Mono code under development based on Microsoft's APIs. Olive code eventually graduates and is moved into the Mono distribution.
C#
16
star
66

monocov

Mono Code Coverage profiler module
C#
15
star
67

debugger

Mono Hard Debugger
C
15
star
68

monodevelop-flatpak

Makefile
14
star
69

gtk-sharp-ribbon

C#
14
star
70

guiunit

A unit test runner which interoperates with any Gui main loop
C#
13
star
71

repo

This is the mono repo - we'll put everything here
13
star
72

monologue

Monologue is Mono's blog aggregation software for the Mono community
C#
12
star
73

gir-sharp

C# binding generator for GIR format
C#
12
star
74

lb

Lame Blog, the lamest blog engine in the world
C#
12
star
75

WindowsAPICodePack

WindowsAPICodePack as imported from MonoDevelop
C#
11
star
76

gluezilla

C
10
star
77

roslyn-binaries

Pre-built binaries of Roslyn
C#
10
star
78

stetic

The Gtk# GUI designer
C#
10
star
79

pty-sharp

API for managing Unix pseudo-terminals from managed code
C
9
star
80

mono-microthreads

Microthreads implementation built on top of Mono.Tasklets library
C#
9
star
81

gnome-keyring-sharp

Bindings to Gnome's KeyRing APIs
C#
8
star
82

nuget-binary

Temporary repo to hold nuget binaries for use with MonoDevelop
8
star
83

winforms-tools

Open source Windows.Forms tools.
C#
8
star
84

old-code

Old mono code that has not been developed in years
C#
8
star
85

gio-sharp

Bindings to Glib's libgio
C#
8
star
86

gnome-sharp

Bindings to the core Gnome APIs
C#
8
star
87

crimson

C#
8
star
88

mooncodecs

open source codecs that can be plugged into Moonlight or Silverlight applications
C#
7
star
89

rocks

Mono.Rocks is a library of utility functions
C#
7
star
90

release

(Deprecated, no longer used) Tools to manage Mono's releases (scripts, web pages, build files)
HTML
7
star
91

WebAssembly.JSInterop

WebAssembly JSInterop library
JavaScript
7
star
92

linux-packaging-fsharp

Packaging metadata for mono-project.com packages
F#
7
star
93

nuget

Nuget
C#
6
star
94

monohotdraw

Vector drawing program
C#
6
star
95

dbus-sharp-glib

Managed dbus
C#
6
star
96

Mono.Simd.Math

Math library that uses Mono's accelerated Mono.Simd library
C#
6
star
97

eglib

C
6
star
98

heap-buddy

C#
6
star
99

boringssl

Custom version of Boring SSL used by Mono
C
6
star
100

google-sharp

C#
6
star