source a script from gdb - shell

Before I debug or execute a program on my system at work, I have to source a file that contains numerous paths and settings that are specific to each project. Is there a way I can do this from gdb? I tried putting it into a .gdbinit file in the working directory, but that doesn't seem to be working. I tried to see if the environmental variable was set by typing
(gdb) shell echo $MY_VAR
and it was blank. Any ideas?

Basically to set the environment variable in the command prompt, you can use the set environment varname [=value]. More information is present here. Since you have noted down there are huge number of paths to be set, you can add them to a file like myGdbSrc and then load them explicitly using source [-s] [-v] filename. You can find details on loading a file here.
I have tried both of them and it works.
HTH.
PS: I have tried it on GNU GDB 6.6 version on SUSE Linux. However, it must work across all version since it seems to be basic command.

How about writing a wrapper script which sources your settings before loading gdb?
E.g. some trivial example:
#!/bin/sh
source my-script-which-sets-up-the-environment
gdb $*
This can of course also add arguments to the gdb invocation to setup paths, load a gdb script, etc.

Related

Trouble installing haskell: how to adjust PATH variable to add to a shell config file?

I installed Haskell on my MacOS system using ghcup installer. It worked because if I type ghci I am dropped into this interactive shell. However I got this message in the terminal after doing the install:
In order to run ghc and cabal, you need to adjust your PATH variable.
You may want to source '/Users/user1/.ghcup/env' in your shell
configuration to do so (e.g. ~/.bashrc).
Detected bash shell on your system...
If you want ghcup to automatically add the required PATH variable to "/Users/user1/.bashrc"
answer with YES, otherwise with NO and press ENTER.
YES
grep: /Users/user1/.bashrc: No such file or directory
My shell is bash 3.2 But as you can see, when I typed YES it says there is no such file. How do I find my shell configuration file, or resolve this? I'd like to complete the setup correctly here.
And I have to be honest about my level of knowledge here, I don't truly understand what this is asking exactly. Is the PATH variable 'env'?
On macOS, .bashrc does not exist by default. ghcup will create this file, so the command you ran will have worked correctly. However, one of ghcup's subcommands expected to find the file before it was created, and therefore reported that error message. You can safely ignore this.

how to put source command in .cshrc file with arugment

I am trying to put a source command in my .cshrc file with an argument at the end, but its not working. The command is below (it works when i run in on the terminal, just not from the .cshrc file). how should i get it to work?
I have tried putting the command in brackets and ""s I have also tried the bottom code.
source /opt/intel/composer_xe_2013_sp1/bin/compilervars.csh ia32
when i source my .cshrc file i get setenv: Too many arguments.
set INTEL = (ia32)
source /opt/intel/composer_xe_2013_sp1/bin/compilervars.csh $INTEL
You have:
set INTEL = (ia32)
This will make a list, rather than a string variable.
From reading the Intel documentation – which I found with a 10-second internet search – it seems you almost certainly want:
set INTEL = ia32
It's also possible that the $INTEL variable is used by the compilervars.csh script, so if that doesn't fix it try renaming it.

Running Bash Script on XCode Compile -- Where To Get List of Build Variables?

When using XCode to compile a Cocoa application, I'm running a custom Bash script in the build phase. Unfortunately, I'm having to spell out full paths. Instead, I'm almost certain there are variables I can use in the Bash and one of those might cover it. Here's what I'm running:
/Users/mike/Projects/objectivec/proj1/proj1/shellscript.sh /Users/mike/Projects/objectivec/proj1/proj1/proj1/lang/en/html/
See how having a $VAR would help here, rather than specifying physical paths? It would also help members on my team be able to compile this project without modification.
I tried looking in the XCode7 docs, but couldn't find any listing anywhere of what these variables might be that I can use.
Note that the path /Users/mike/Projects/objectivec/proj1/proj1/ folder contains my AppDelegate.mm file in this case, if that helps you.
Can you tell me where I can find the documentation on this list of available variables so that I don't have to specify full physical paths?
The fix was that I made it run this Bash script as a test:
#!/bin/bash
set > /tmp/vars.txt
Then, I compiled a build. After that, I looked in /tmp/vars.txt to see what was available to use. From there, I could use these directly both in my custom Bash script and in the black script field inside XCode, such as $SOURCE_ROOT.

Where is GDB's gdbinit file when using cygwin?

I would like to follow the answer in this question:
Permanently Change Disassembly Flavor in GDB
but it refers to a GDB file named .gdbinit. What is the equivalent file when using GDB through cygwin?
gdb help output tells you where it's looking at startup:
$ gdb --help | tail
Set GDB's data-directory to DIR.
At startup, GDB reads the following init files and executes their commands:
* user-specific init file: /home/davidw/.gdbinit
* local init file (see also 'set auto-load local-gdbinit'): ./.gdbinit
For more information, type "help" from within GDB, or consult the
GDB manual (available as on-line info or a printed manual).
Report bugs to "<http://www.gnu.org/software/gdb/bugs/>".
You can also get a little more information from within gdb with the command
show autoload.
See also the online manual here.
Not really relevant to this question, but the reason I spent time looking into this was that, with cygwin, my .gdbinit seemd to be getting ignored. It turned out to be the command in my .gdbinit that was being ignored.

Setting an environment variable in Cygwin

I have been trying to setup a environment variable in Cygwin using the command export PRIMOSBASE=/directory/for/primosfiles.
And when i check the variable using the command echo $PRIMOSBASE it shows the /directory/for/primosfiles. hopeful this means the environment variable is set.
But when i try to run a shell script(primos) for the /directory/for/primosfiles, it shows
./primos: line 8: /prilaunch.pl: No such file or directory
chmod: failed to get attributes of `step1.sh': No such file or directory
which means i have not set the PRIMOSBASE environment. could anyone please tell me where i am going wrong...
Thanks ...
Run
echo "export PRIMOSBASE=/directory/for/primosfiles" >> ~/.bashrc
to append the command to the end of your .bashrc file, so that the variable is set each time you use Cygwin. Then run
source ~/.bashrc
to make it take effect immediately.
NOTE: Make sure you use double brackets (>>) to append. It might be a good idea to make a backup of .bashrc just in case. If you're not comfortable with I/O redirection, an alternative is to edit .bashrc with an editor. I think vim is among the default tools in Cygwin.
I had a similar issue trying to get ANDROID_HOME to work in a Cygwin window. When I used the linux path separators, as follows
ANDROID_HOME=/cygdrive/c/Users/User/AppData/Local/Android/sdk my gradlew build script complained it couldn't find the sdk in ANDROID_HOME.
I eventually discovered that I had to set my environment variable in the Windows format, including Windows path separators '\', as follows
ANDROID_HOME=C:\Users\User\AppData\Local\Android\sdk
Note: the PATH and several other environment variables set in Windows are converted into Linux format. I hope this helps others who want/need to use Cygwin + Windows + essentially Windows programs that need environment variables.

Resources