How to execute a command only for particular arch? - gdb

I'm trying to make a generic gdbinit for both native and remote GDB, where native is i386, and remote is ARM. For i386 I have set disassembly-flavor intel command, which breaks initialization for ARM-targeted GDB.
The only thing I found which lets me know arch (at least i386 vs ARM) is
show arch command, but it just prints its output to stdout, not allowing me to get it for comparison.
So, is there any way to execute a command only for some architectures but not not ohers?

You could just ignore the error using the Python plug-in:
python
try:
gdb.execute("set disassembly-flavor intel")
except:
pass
end
Or you could check the architecture:
python
if "(currently i386)" in gdb.execute("show arch", to_string=True):
gdb.execute("set disassembly-flavor intel")
end

Related

gdb script: How can a script determine if it is invoked under `gdb` or `gdb-multiarch`?

I'd like to define a command which does X under gdb-multiarch, but prints out a helpful message when run under normal gdb. How can my script determine which of the two its run under?
Why? When I start gdb-multiarch, I can bind to a qemu-arm session. When I try that in gdb, I get bizarre errors. It's easy to forget and run gdb (and not -multiarch), and I want to my bind-to-qemu tell me "This must be run under gdb-multiarch".
Your question presumes that there is some difference between gdb and gdb-multiarch, but there doesn't have be any such difference.
Presumably on the OS you are using the gdb and gdb-multiarch are configured differently, with gdb only supporting native architecture, while gdb-multiarch supports cross-architecture debugging.
Presumably what you actually want to detect is that the target-architecture you need (arm ?) is / isn't supported by the current binary.
In the bind-to-qemu user-defined function, you can try to set architecture arm.
If that errors out, the rest of bind-to-qemu should not execute.

pyOCD, gdb instantly terminate in Eclipse

TL;DR: A debug toolchain which works perfectly outside of Eclipse terminates automatically when started in Eclipse.
OS: macOS Sierra 10.12.3
IDE: Eclipse IDE for C/C++ Developers, Mars.2, Release 4.5.2
Target Board: WIZwiki-W7500P (via CMSIS-DAP for interactive debugging)
Embedded Platform: mbed-os 5.4
On-chip Debugger: pyOCD 0.8.1a1
Debugger: arm-none-eabi-gdb 7.12.0.20161204-git
Compiler: arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors) 6.2.1 20161205
Following this tutorial, my aim is to use gdb to debug in Eclipse. Via command line,
$ pyocd-gdbserver
successfully starts the server and detects the board, and
$ arm-none-eabi-gdb
successfully starts the debugger and can connect to the server. The program successfully compiles to binary via mbed-cli:
$ mbed compile -t GCC_ARM -m WIZWIKI_W7500P
and flashes to the board, and executes without issue.
In addition, an .elf is generated which can be interactively debugged, breakpoints can be added, and functions can be stepped-through while running on the board.
Finally, the program appears to export successfully to Eclipse:
$ mbed export -t eclipse_gcc_arm WIZWIKI_W7500P --profile mbed-os/tools/profiles/debug.json
including the automatic generation of a Makefile, which successfully orchestrates building in Eclipse.
However, in Eclipse both gdb and pyocd-gdbserver terminate shortly after beginning debug with the following output (despite being configured exactly as they are when I run them in my terminal):
gdb traces:
650,101 2-gdb-show language
650,102 2^done,value="auto"
650,102 (gdb)
650,103 3-data-evaluate-expression "sizeof (void*)"
650,104 3^done,value="4"
650,104 (gdb)
650,104 4-gdb-set language auto
pyocd-gdbserver (n.b. only the last line is different from what's seen in terminal):
WARNING:root:Unsupported board found 2203
INFO:root:DAP SWD MODE initialised
INFO:root:ROM table #0 # 0xe00ff000 cidr=b105100d pidr=4000bb471
INFO:root:[0]<e000e000:SCS-M0+ cidr=b105e00d, pidr=4000bb008, class=14>
INFO:root:[1]<e0001000:DWT-M0+ cidr=b105e00d, pidr=4000bb00a, class=14>
INFO:root:[2]<e0002000:BPU cidr=b105e00d, pidr=4000bb00b, class=14>
INFO:root:CPU core is Cortex-M0
INFO:root:4 hardware breakpoints, 0 literal comparators
INFO:root:2 hardware watchpoints
INFO:root:Telnet: server started on port 4444
INFO:root:GDB server started at port:3333
Started by GNU ARM Eclipse
Outcome:
I've reinstalled each component, begun a fresh workspace and experimented with preferences such as:
How do I prevent this debug system from terminating?

Loading Intel environment variables with shell script

I installed the Intel ifort compiler on my computer but before I can executed the command ifort I need to load the file:
. /opt/intel/composerxe/bin/compilervars.sh intel64
I don't want to load this in every session, therefor I don't want to put
it in my ~/.bashrc.
When I put this line in a Shell Script, like this:
#!/bin/sh
echo "Load environment variables for Intel ifort + Intel MPI"
. /opt/intel/composerxe/bin/compilervars.sh intel64
I get this error:
ERROR: Unknown switch ''. Accepted values: ia32, intel64
Is there another way to source the compilervars.sh with the intel64 flag?

How to control the cl.exe command that nvcc builds

I just installed CUDA 6.5, VS2013 Community Edition, and pyCUDA. I already had python 2.7.8 installed. I am new to CUDA and VS2013 development but not python. I verified my CUDA install by building some of the CUDA VS2013 sample solutions as both 32- and 64-bit so things work up to that point.
Now I'm trying to verify my pyCUDA install by running this test program.
### from: http://documen.tician.de/pycuda/tutorial.html
import pycuda.gpuarray as gpuarray
import pycuda.driver as cuda
import pycuda.autoinit
import numpy as np
# copy to gpu
a_gpu = gpuarray.to_gpu(np.random.randn(4,4).astype(np.float32))
# double it
a_doubled = (2 * a_gpu).get()
print('a_doubled', a_doubled)
When run, it produces this error:
[snip]
File "B:\Anaconda2\lib\site-packages\pycuda-2014.1-py2.7-win-amd64.egg\pycuda\compiler.py", line 250, in do_compile
return compile_plain(source, options, keep, nvcc, cache_dir)
File "B:\Anaconda2\lib\site-packages\pycuda-2014.1-py2.7-win-amd64.egg\pycuda\compiler.py", line 132, in compile_plain
stderr=stderr.decode("utf-8", "replace"))
CompileError: nvcc compilation of e:\temp\cb4\tmpadhjeh\kernel.cu failed
[command: nvcc -cubin -keep -cudart shared -arch sm_52 -m64 -Ib:\anaconda2\lib\site-packages\pycuda-2014.1-py2.7-win-amd64.egg\pycuda\cuda -keep kernel.cu]
[stdout:kernel.cu]
[stderr:
'B:\VisualStudioCom2013\VC\bin\amd64"\cl.exe #kernel.cpp1.ii.res > "kernel.cpp1.ii' is not recognized as an internal or external command,
operable program or batch file.]
Note the extraneous double quotes in the cl.exe command which are causing the error. Without them I can manually run B:\VisualStudioCom2013\VC\bin\amd64\cl.exe #kernel.cpp1.ii.res > kernel.cpp1.ii. It completes just fine and a valid kernel.cpp1.ii is generated.
Is there some way to control the cl.exe command that nvcc builds? Nothing in the nvcc manual jumped out at me, but with all those options I certainly might've have missed it.
Also posted in this Nvidia developers forum.
This is a bug in nvcc for CUDA 6.5. After following #talonmies suggestion to look through nvcc.profile, I started trying combinations of profile settings and command line options. I narrowed it down to this: when --keep is on the command line AND compiler-bindir is in the nvcc.profile, the malformed cl.exe compile command that includes double quotes is generated. The solution for keeping intermediate files is to put cl.exe in the path and remove compiler-bindir from nvcc.profile. Logged as a bug to NVIDIA.
UPDATE:
The problem does not manifest in CUDA 7.0.

strange gdbserver output shows at my target device

when I run gdbserver on uclinux target device blackfin bfin537/stamp it work perfectly but it always generates annoying output
Request to get for unknown register 232
Request to get for unknown register 236
it is extremely annoying since each step out or step in gdb client results several of that error on the output screen terminal RS232 I was recommended to change the bfin compiler version and rebuild gdb server with different version of uclinux ,.... none of them worked and even compiling my code with different versions of bfin-uclinux-gcc didn't solve my problem.
I decided to recompile gdbserver.c and eliminate the line that generates the error but in fact that line does not exists in any of the gdbserver related files for compiling.
I decided to suppress the stderr output of gdb server by running gdbserver :3298 process 1>/dev/null 2>/dev/null but this didn't solve it
how can I configure my gdb client to asks for specific registers (bfin-uclinux-gdb) related to bfin537-stamp?
I think this error originates somewhere else in uclinux system background system processes.
I want to find which process writes in stderr,stdout which I am unaware of It and I want to suppress its outputs?
Shall I change something in the busybox shell or /bin/bash to eliminates all stderr outputs
which means if I send all the parent shell output or stderr to /dev/null
Thanks