Programmatic interaction with gdbserver - gdb

The gdbserver program allows for the remote debugging of programs. Typically, a local copy of gdb is used to interact with the remote gdbserver instance, and the program running under that remote gdbserver.
My question is: Are there client implementations of the gdb remote serial protocol (RSP) that allow programs other than gdb to interact with the gdbserver program?
This document discusses the implementation of an RSP server, but it is the client side I am primarily interested in. This implementation supports client and server, but is implemented in common lisp, and is not yet a mature library.

The remote gdb protocol is fully documented in the gdb manual, which is available online at
http://sourceware.org/gdb/current/onlinedocs/gdb_toc.html
You have gdb to look at as a working example -- this should be enough to allow you to write a client to control gdbserver over the serial protocol. ;-)

I am not aware of any clients of the GDB protocol.
Why would you want one?
For simple tasks (starting; stopping; examining memory addresses) you can write one from scratch pretty quickly.
For complicated tasks (unwinding stack, examining variables, etc.) you'd have to re-implement significant parts of GDB; and that should probably not be attempted without a very good reason.
Also note that GDB/gdbserver protocol is constantly evolving; there are provisions to let newer GDB deal with older gdbserver, but I am not sure if the reverse is also true.

Related

Strategy for simple yet effective UDP server for gaming (and other tasks)

i'm trying to implment my idea of simple yet pretty effective multithreaded server working on UDP. Main goal is for gaming(-like) applications, but it would be good if it could be used in other purposes too.
I want to use this API/technologies etc
STD::Thread for multithreading, since it is part of C++ standard, it should be future-proof and as far as i seen it it's both simple and works well with C++.
BSDSock (Linux) & WinSock2 (Windows). I would create one abstract class called Socket and for each platform (Linux - BSD, Windows - WinSock) create derived class implementing native API. Then i would use API provided by base class Socket, not native/platform API. That would allow me to use one code for whole server/client module and if i want to change platform i'd have to just switch class type of socket and thats it.
As for strategy of server-client comunication i thought of something like this:
Each programm has two sockets - one that listens on specified port and one that is used to send data to server/other clients. Both sockets run on different threads so that i can both read and send data at the same time (sort of), that way waiting for data won't ruin my performance. There will be one main server, and other clients will connect directly to that server. Clients will send only their data and recieve data directly from server.
Now i have some question:
Is it wise to use STD::Thread? I heard it's good on Linux, but not that good on Windows. Would PThreads would be much better?
Any other interesting ideas about making one code for many platforms (mainly Linux&Windows)? Or mine is good enough?
Any other ideas or some tips about strategy for how server/client would work? I wrote some simple network apps, but it didn't need that good strategy, so i'm not sure if it's best from simple ideas.
How often should i send data from client to server (and from server to client)? I dont want to flood the network and to make server load 100%?
Also: it should work nice with 2-4 players at the same time, i don't plan to use it with more at the moment.
Intuitively, from multi-threading purposes Linux + Pthread would be a nice combination. A vast number of mission critical systems are running on that combination. However, when we come to std::thread, having platform dependent nature is a nice to have feature. Certainly, if some bad smells are in windows dialect, MS would correct them future. BUT, if I were you, I will certainly select Linux + std::thread combination. Selection of Linux over Windows is a different topic and no need to comment here (with respect to server development perspective). std::thread provides you a nice set of feature,yet having the power of pthreads.
Regarding UDP, you have both pros and cons. But, I'd say if you are going to open your sever for public, you have to think about network firewalls as well. If you can address the inherent transport layer issues of UDP (packet re-ordering, lost packet recovery), a UDP server is light weighted in most of the cases.
It depends on your game to decide how often you need to send messages. I can't comment it.
Moreover, pay your attention to extra security on your data communication more seriously. Sooner or later your sever will be hacked. It is just a matter of fact of TIME.

Why libcurl needs `CURLOPT_NOSIGNAL` option and what are side effects when it is enabled?

I spent a lot of time to investigate why multithreaded libcurl application crashes on Linux. I saw in forums that I have to use CURLOPT_NOSIGNAL to bypass this problem. Ok, no problems, but are there any information what side effects can it create? If CURLOPT_NOSIGNAL = 0 is buggy, why libcurl needs this option at all nowadays when even mobile devices have multicore processors and that is why a lot of applications use multiple threads to use this hardware multitasking support?
By default the DNS resolution uses signals to implement the timeout logic but this is not thread-safe: the signal could be executed on another thread than the original thread that started it.
When libcurl is not built with async DNS support (which means threaded resolver or c-ares) you must set the CURLOPT_NOSIGNAL option to 1 in your multi-threaded application.
You can find more details related to this topic here:
http://curl.haxx.se/libcurl/c/libcurl-tutorial.html#Multi-threading
http://www.redhat.com/archives/libvir-list/2012-September/msg01960.html
http://curl.haxx.se/mail/lib-2013-03/0086.html
Why libcurl needs this option at all nowadays?
Mainly for legacy reasons, but also because not all applications use libcurl in a multi-threaded context.
This is still something that is actively discussed. See this recent discussion:
libcurl has no threads on its own that it needs to protect and it doesn't know
what thread library/concept you use so it cannot on its own set the callbacks.
This has been the subject for discussion before and there are indeed valid
reasons to reconsider what we can and should do, but this is how things have
been since forever and still are. [...] but I'm always open for further discussions!

Information need to pass to another thread

I am a newbie programmer in linux domain. I am basically a MicroController programmer familiar with C. Now I am into little PC programing and need some inputs.
I am opening a socket and sending a Broadcast looking for my Embedded device on network. First I am probing the interfaces on the machine and will be broadcasting in each subnet, a call to my device with a signature. The device is listening on that particular port and it responds with its signature. The program then gets the ip and other details of my device and will start communicating.
I am sending a call in one function in each interface and to avoid blocking I am creating another listening thread to get response which may take some time to arrive. On receiving response I need to inform other thread about this and data to be given to them.
In this scenario, which is the best method to do that? Signal, Message or flag or whatever?
Since I need to implement this code in windows also, it will be good if it is possible to use a mechanism which is possible in both platforms.
Please suggest
Roy Thomas
It is a classic network programming issue. Personally, when I do network programming at this level in C++ , I use the C++ POCO libraries (see this).
You do not specify whether you use UDP or TCP. If you use TCP, the library provides something called TCPServer framework that deals with these issues, i.e. managing a pool of worker threads that deals with connections.
These slides, starting at slide "The TCPServer Framework", explain the principle.
Then you can use FIFO to communicate between your threads or POCO libraries notifications.
Have a look at Qt Creator its a cross platform C++ IDE it has very good implementation for signals and slots.
Its got its own library of functions that extend the STL and some very nice threading ones that you should take a look at.
I know this may not have been the answer you were looking for but i use Qt every day and its great! so feel free to ask any questions ...

Using ptrace to write a program supervisor in userspace

I'll looking for advice/resources to write a program that can intercept system calls from a programm to supervise it's filesystem, network, etc access.
The aim of this is to write an online judge, so that untrusted code can be run safely on a server.
This is on linux, and I would prefer to write C++ or a scripting langauge (ruby, python, etc), and a library would be great!
Thanks.
This looks like a good place to start.
http://www.linuxjournal.com/article/6100
You can't safely use ptrace() to sandbox a hostile application.
The application can always use multiple threads with deliberate race conditions to alter syscall arguments passed via pointers (eg. a filename) after you've inspected them but before the kernel looks at them.

C++: Most common way to talk to one application from the other one

In bare outlines, I've got an application which looks through the directories at startup and creates special files' index - after that it works like daemon. The other application creates such 'special' files and places them in some directory. What way of informing the first application about a new file (to index it) is the most common, simple (the first one is run-time, so it shouldn't slow it too much), and cross-platform if it is possible?
I've looked through RPC and IPC but they are too heavy (also non-cross-platform and slow (need a lot of features to work - I need a simple light well-working way), probably).
Pipes would be one option: see Network Programming with Pipes and Remote Procedure Calls (Windows) or Creating Pipes in C (Unix).
I haven't done this in a while but from my experience with RPC, DCOM, COM, .NET Remoting, and socket programming, I think pipes is the most straightforward and efficient option.
For windows (NTFS) you can get notification from OS that directory was changed. But it is not crosspl. and not about two apps.
"IPC but them are too heavy" - no no, they are not heavy at all. You should look at named pipes - this IPC is fastest and it is in both Win/Unix-like with slight differences. Or sockets!
eisbaw suggested TCP. I'd say, to make it even more simple, use UDP.
Create a listening thread that will receive packets, and handle it from there - on all applications.
Since it is on the same PC you'll never lose any packet, something that UDP could mistakenly do when on network.
Each application instance will need a special port but this is easy to configure with configuration files that you (I assume) already have.
Keep it simple (:
Local TCP sockets are guarenteed to work - as already mentioned by Andrey
Shared memory would be another option, take a look at
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2044.html
As Andrey noted, if you agree on the full path ahead of time, you can just have the OS tell you when it's added. All major platforms actually support this in some form. You can use a cross-platform library for this, such as QFileSystemWatcher.
EDIT: I don't think QFileSystemWatcher will cause too much of a performance hit. It definitely relies on the underlying OS for notifications on Linux, FreeBSD, and Mac OS (and I think Windows). See http://qtnode.net/wiki/QFileSystemWatcher
memory mapped files, socket, and named pipes are all highly efficient, cross platform, ipc mechanisms. Well, the apis to access named pipes and memory mapped files differ between POSIX and Win32, but the basic mechanisims are similar enough that its easy to make a cross platform wrapper. Sockets and named pipes tend to be fast because, in inter-process situations, the OS developers (of most common OSs) have built in shortcuts that essentially makes the socket / named pipe write a rather simple wrap of a memory section.