GDB: Append to solib-search-path - gdb

How can I append to the contents of solib-search-path?
I would like to do smothing like:
set solib-search-path $(solib-search-path):some/other/path

There isn't a simple built-in way to do this. There are two less simple ways, though.
The simplest of the two ways is to use Python scripting to change the setting. From Python it is easy to get the current value and modify it as a string.
The harder way is to use a combination of set logging, shell, and source to do it. The idea is to print the current value to a file, rewrite the file to be the new set command, and then source the result.

Related

gdb script, assign functions' return value in user variable

I would like to assign the "info sharedlibrary" value to a variable in user define function.
Such as,
define customFunction
set $i = info sharedlibrary
end
But it seems impossible in gdb
And also i cannot use python script too...
Is there any way to do this??
Thank you
ps. I trying to do this because i want to print only selected library's instructions.
You don't mention why you can't use a Python function. That's by far the simplest way to program gdb.
However, if you really must do it, and really must avoid Python, there is a way. It's gross! But it does work. It's like this:
Use the various set logging commands to redirect output to a temporary file.
Invoke the command you want.
Use set logging again to disable logging.
Use the shell command to run sed or perl or what-have-you on this temporary file to turn it into a sequence of gdb commands, say commands to set a variable, or commands to print exactly the output you want.
source the resulting file

Modifying a configuration file

I want to modify value corresponding to a key in configuration file using cpp.
Eg:
key=value
has to be changed to
key=new_value
I works with 'sed' command, but is there some possible way to do it using cpp way.
Implementation fails when the string to be changed is less than the existing one. Is that not really possible using cpp?
You basically only have one option: Rewrite the configuration file, write out all configuration options from the start.
Trying to move around contents of a text file if one line changes length (bigger or smaller) is possible, but it's much more work than just rewriting it.
It's either that or the working solution using sed, which can be called from inside the program using the system function.

Modifying a complex config file in C/C++

I need to be able to modify a complex config file from within my C/C++ program (whichever is going to be easier and more convenient to use in this case, probably C++). The idea is that the program computes the values that it needs to insert into the file, then writes them.
The config file itself looks like this:
^looots of stuff I won't be using^
option blah.blah.something "value"
option blah.blah.someotherthing "value"
Now, many of the options are logically connected, for instance:
option blah.blah.car.engine "value"
option blah.blah.car.color "value"
I don't really have an idea how to reach those lines that I'm interested in. Should I skip to a specific line and then search for a quotation mark and modify what's after it? That doesn't seems like a reliable and flexible solution, does it?

Reload option values in boost::program_options from new source

I'm just starting to dig into boost::program_options for the first time. I like it quite a bit. However, what I'm trying to accomplish with it doesn't seem to be something its designers have accounted for.
I want to use boost::program_options to parse both command line options as well as config files. So far so good. Additionally, though, I would like to be able to check for updated settings (say from a new config file) that could override the previously parsed settings in my variables_map.
Granted, I could do a separate parse and try to merge the two maps. Perhaps that's what I'll end up doing. I'm just wondering, though, if anyone has done anything like this before and has come up with a slick solution.

C++ Passing Options To Executable

How do you pass options to an executable? Is there an easier way than making the options boolean arguments?
EDIT: The last two answers have suggested using arguments. I know I can code a workable solution like that, but I'd rather have them be options.
EDIT2: Per requests for clarification, I'll use this simple example:
It's fairly easy to handle arguments because they automatically get parsed into an array.
./printfile file.txt 1000
If I want to know what the name of the file the user wants to print, I access it via argv[1].
Now about how this situation:
./printfile file.txt 1000 --nolinebreaks
The user wants to print the file with no line breaks. This is not required for the program to be able to run (as the filename and number of lines to print are), but the user has the option of using if if s/he would like. Now I could do this using:
./printfile file.txt 1000 true
The usage prompt would inform the user that the third argument is used to determine whether to print the file with line breaks or not. However, this seems rather clumsy.
Command-line arguments is the way to go. You may want to consider using Boost.ProgramOptions to simplify this task.
You seem to think that there is some fundamental difference between "options" that start with "--" and "arguments" that don't. The only difference is in how you parse them.
It might be worth your time to look at GNU's getopt()/getopt_long() option parser. It supports passing arguments with options such as --number-of-line-breaks 47.
I use two methods for passing information:
1/ The use of command line arguments, which are made easier to handle with specific libraries such as getargs.
2/ As environment variables, using getenv.
Pax has the right idea here.
If you need more thorough two-way communication, open the process with pipes and send stuff to stdin/listen on stdout.
You can also use Window's PostMessage() function. This is very handy if the executable you want to send the options to is already running. I can post some example code if you are interested in this technique.
The question isn't blazingly clear as to the context and just what you are trying to do - you mean running an executable from within a C++ program? There are several standard C library functions with names like execl(), execv(), execve(), ... that take the options as strings or pointer to an array of strings. There's also system() which takes a string containing whatever you'd be typing at a bash prompt, options and all.
I like the popt library. It is C, but works fine from C++ as well.
It doesn't appear to be cross-platform though. I found that out when I had to hack out my own API-compatible version of it for a Windows port of some Linux software.
You can put options in a .ini file and use the GetPrivateProfileXXX API's to create a class that can read the type of program options you're looking for from the .ini.
You can also create an interactive shell for your app to change certain settings real-time.
EDIT:
From your edits, can't you just parse each option looking for special keywords associated with that option that are "optional"?