Introduction
Debugging software applications typically occurs within the context of an IDE (integrated development environment), such as Eclipse, XCode, Visual Studio, etc. This allows developers to step line by line through sections of code, analyzing variables, and tracing the stack. Occasionally, developers may be unable to debug within the IDE, whether due to software complexity, runtime environments, or other issues. During these conditions, resourceful developers may utilize more primitive, but equally powerful methods of debugging, such as raw printing of values and steps (printf, cout, alert statements, etc). However, when the software process executes in a remote server environment, where the developer may not have access to the local file system, debugging can take on additional complexity. Common remote debugging solutions include writing logs to the file system, email, or remote web service methods.
In this tutorial, we’ll discuss using the Pastebin web service to assist with remote debugging. We’ll include a simple code sample for accessing the Pastebin API and posting output.
What is Pastebin?
Pastebin is an online service for posting and uploading any type of text. After posting, pastebin provides a short link for accessing the post or sharing with others. Pastebin, along with a list of other simple text posting services, are usually easy to use and can be particularly useful for cases of simplified remote debugging.
All Code Should Work Locally, Of Course
Software environments vary by organization and stage, including development, QA, and production. In a perfect world, software functions the same, whether installed on different machines or staging environments. However, as subtle differences may exist within each environment, developers may find that code operates differently when deployed to different locations. This may be as a result of security differences, linked libraries, installed software, or other conditions. However, this usually results in the need for remote debugging.
Limitations of Remote Debugging
Depending on the IDE, remote debugging usually requires debugging software to be installed on the remote server (such as, Visual Studio’s remote debugging service), which allows the IDE to link to the remote server while executing code. In some cases, the developer may have limited access to the remote machine, specifically with regard to installing software.
On to the File System
In cases where software installation access is limited on the remote machine, the next method of debugging is typically to print to a local log file, registry, or email. Variables, lines, output, and other values may be logged to a file or sent by email for retrieval by the developer. This method works exceptionally well as a fallback for many types of debugging. However, in certain cases of debugging where software complexity or integrated software is involved, local logging may be unavailable.
To the Web and Beyond
When local file logging fails, an alternative solution can be web service logging. Web service logging can often take the same debugging content as a a file, email, or registry log. This allows the developer to easily monitor a web-based log to track the performance of the application. The easier the web service is to integrate with, the easier the task of remote debugging. One (of many) easy web services for posting simple text, includes Pastebin.
The Pastebin Client
Pastebin provides an easy URL-based API for automatically posting text from a variety of applications. We can take advantage of the Pastebin API to post our software application’s debug output by creating a simple Pastebin client in C# .NET to automatically upload text to pastebin, as follows:
1 | public static class PasteBin |
The above code can be similarly used with almost any text storage web service. The code simply wraps a web request to the pastebin API service, and passes in the developer API key. The codes sets the option for “Paste”, indicating that we are creating a new Pastebin document, provides the text to post, and sets the post to private.
Our software application under test can now utilize the Pastebin client to post debug output logs.
Using the Pastebin Client
Using the pastebin client code is as simple as the following example:
1 | static void Main(string[] args) |
Of course, in your actual application being debugged, you could include the PasteBin.Create() call in each place where you would typically include a printf() statement to output a variable or step. Utilizing a text-posting web service in this manner provides another tool in the developer’s arsenal, helping to increase software development productivity.
Finally, a Word on Responsibility
In any case where 3rd-party web services are involved, it’s important to keep in mind security and privacy considerations. This is especially the case when posting, potentially sensitive, software debug output. In cases where security and privacy of the outputted debug values are of importance, developers would be better served by creating their own local logging web service, in which case they can post debug info to a locally provided url. However, in cases where software application debug information is non-sensitive, web services can be an excellent tool for remote debugging productivity.
Download @ GitHub
The source code for this example is available online in our GitHub repository.
For VSCode, the source code for this example is available here.
About the Author
This article was written by Kory Becker, software developer and architect, skilled in a range of technologies, including web application development, machine learning, artificial intelligence, and data science.
Sponsor Me