Pass CTRL+C to Cmake custom command under VSCode - visual-studio-code

I have a Cmake custom target that runs a command-line tool which has to be stopped using CTRL+C. If I run the tool from the terminal, it stops on CTRL+C just fine, but if I build my custom Cmake target, it's impossible to terminate it. I tried to add the USES_TERMINAL option to the Cmake target, but that doesn't change anything. Is there a Cmake or VSCode option that I have missed which would allow me to send SIGINT to a Cmake command?
Here's a small project to reproduce the situation:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.2.0)
project(test_prj LANGUAGES CXX C)
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "ON")
add_executable(test_prj main.c)
add_custom_target(test_run COMMAND test_prj USES_TERMINAL)
main.c:
#include <signal.h>
#include <stdio.h>
char flag = 1;
void sig_handler(int signum) {
flag = 0;
}
int main(void) {
signal(SIGINT, sig_handler);
while(flag);
printf("success\n");
return 0;
}
Once test_prj is compiled, running it in the terminal
PS C:\22_Test\build> ./test_prj.exe
<I hit CTRL-C here>
success
However, building test_run results in the following output:
[main] Building folder: 22_Test test_run
[build] Starting build
[proc] Executing command: C:\tools\cmake\3.20.2\bin\cmake.EXE --build c:/22_Test/build --config Debug --target test_run --
[build] [1/3 33% :: 0.108] Building C object CMakeFiles/test_prj.dir/main.c.obj
[build] [2/3 66% :: 0.345] Linking C executable test_prj.exe
[build] [3/3 66% :: 0.345] cmd.exe /C "cd /D C:\22_Test\build && C:\22_Test\build\test_prj.exe"
<I hit CTRL-C here, nothing happens>

Related

libopencv_highgui.so.3.4: cannot open shared object file: No such file or directory in the eclipse ide for cross compiler

I have stucked a problem. I develop cross-compile for the embedded system. I built the opencv for arm_linux-gnueabihf.
My ubuntu version is 18.04.2 x86_64 5.3.0.51-generic.
The problem that
libopencv_highgui.so.3.4: cannot open shared object file: No such file or directory
I build the project success but when I run the project, I get the problem
this my code
#include <iostream>
#include <stdio.h>
#include <cv.h>
#include <opencv2/videoio.hpp>
#include <opencv2/core.hpp>
#include <opencv2/core/mat.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main(int, char**){
Mat frame;
VideoCapture cap;
int deviceId = 0;
int apiId = cv::CAP_ANY;
cap.open(deviceId,apiId);
if (!cap.isOpened()){
cerr<<"Error! Unable to camera\n";
return -1;
}
for(;;){
// read frame
cap.read(frame);
if (frame.empty()){
cerr <<" ERROR ! black frame grabbed ! \n";
break;
}
imshow("Live",frame);
if (waitKey(5) >= 0){
break;
}
}
return 0;
}
I checked the library as follows:
sudo find / -name "libopencv_highgui.so.3.4"
the command returned as follows
/usr/local/lib/libopencv_highgui.so.3.4
/usr/local/lib/libopencv_highgui.so.3.4.4
/usr/local/include/lib/libopencv_highgui.so.3.4
/usr/local/include/lib/libopencv_highgui.so.3.4.4
I created a file in /etc/ld.so.conf.d/opencv.conf that contain
/usr/local/lib
/usr/local/include
then I run the command that sudo ldconfig -v, and it returned as follow
/sbin/ldconfig.real: /usr/local/lib/libopencv_highgui.so.3.4.4 is for unknown machine 40.
/sbin/ldconfig.real: /usr/local/lib/libopencv_imgproc.so is for unknown machine 40.
/sbin/ldconfig.real: /usr/local/lib/libopencv_xfeatures2d.so is for unknown machine 40.
/sbin/ldconfig.real: /usr/local/lib/libopencv_bgsegm.so.3.4.4 is for unknown machine 40.
/sbin/ldconfig.real: /usr/local/lib/libopencv_objdetect.so.3.4 is for unknown machine 40.
and also other opencv's libraries.
I configured setting of the eclipse for the libraries as follows:
the "Includes" folder that in cross G++ Compiler
"Libraries" folder that in cross G++ Linker
Finally, I added the LD_LIBRARY_PATH in debug of the eclipse setting
I tried sudo apt update and sudo apt upgrade commands,but I still getting the error.
Does any one have any advice ?
the solution is add the "/usr/local/lib" to LD_LIBRARY_PATH in environment.
mine is
LD_LIBRARY_PATH /usr/arm-linux-gnueabihf/lib/:usr/local/lib/

Need some help in Fuzzing Mosquitto lib

Here comes a bug while fuzzing Mosquitto lib, I would like to know the solution.
Step1. compile the lib
#:~/fuzz/fuzzmqtt/mosquitto$ ls
about.html doc Makefile security
aclfile.example docker man SECURITY.md
appveyor.yml edl-v10 misc service
buildtest.py epl-v10 mosquitto.conf set-version.sh
ChangeLog.txt examples Mosquitto.podspec snap
client installer notice.html src
CMakeLists.txt lib pskfile.example test
compiling.txt libmosquitto.pc.in pwfile.example THANKS.txt
config.h libmosquittopp.pc.in readme.md travis-configure.sh
config.mk LICENSE.txt readme-tests.md travis-install.sh
CONTRIBUTING.md logo readme-windows.txt www
#:~/fuzz/fuzzmqtt/mosquitto$ sudo make install CC="clang -O2 -fno-omit-frame-pointer -g -fsanitize=address -fsanitize-coverage=trace-pc-guard,trace-cmp,trace-gep,trace-div" -j2
Step2. compile the fuzzer
#:~/fuzz/fuzzmqtt/mosquitto/lib$ clang -g -O1 -fsanitize=fuzzer,address mos_fuzzer.cc -o mos_fuzzer -lmosquitto
Step3. Run the fuzzer and got the bug
#~/fuzz/fuzzmqtt/mosquitto/lib$ ./mos_fuzzer
INFO: Seed: 106983829
INFO: Loaded 1 modules (2337 guards): 2337 [0x7f157cd816b0, 0x7f157cd83b34),
INFO: Loaded 1 modules (1 inline 8-bit counters): 1 [0x787f80, 0x787f81),
INFO: Loaded 1 PC tables (1 PCs): 1 [0x565af8,0x565b08),
ERROR: The size of coverage PC tables does not match the
number of instrumented PCs. This might be a compiler bug,
please contact the libFuzzer developers.
Also check https://bugs.llvm.org/show_bug.cgi?id=34636
for possible workarounds (tl;dr: don't use the old GNU ld)
The code is as follow
#include "stdio.h"
#include "mosquitto.h"
#include "assert.h"
#include "stdint.h"
#include "stddef.h"
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
bool clean_session = true;
struct mosquitto *mosq = NULL;
mosquitto_lib_init();
void *data_1=(void *)data;
mosq = mosquitto_new(NULL, clean_session, data_1);
mosquitto_destroy(mosq);
mosquitto_lib_cleanup();
return 0;
}
Thank you

INSTRUMENTATION_FAILED when run android automation test from sh

I'm doing automation test for an android app. My test code is ready and good to run from android studio and manual command from android device. But when I change the command to sh, it failed with INSTRUMENTATION_FAILED. Anyone can help me how to fix it? I just don't understand, why it's working when directly run from terminal, but failed when run from sh.
Manual input comment, which is working:
am instrument -w -r -e debug false -e class com.amap.auto.androidautomation.testcases.basemap.SmokeTest com.amap.auto.androidautomation.test/android.support.test.runner.AndroidJUnitRunner
Result:
INSTRUMENTATION_STATUS: numtests=9
INSTRUMENTATION_STATUS: stream=
com.amap.auto.androidautomation.testcases.basemap.SmokeTest:
INSTRUMENTATION_STATUS: id=AndroidJUnitRunner
INSTRUMENTATION_STATUS: test=smoke01
INSTRUMENTATION_STATUS: class=com.amap.auto.androidautomation.testcases.
Run from sh:(the command is the same as manual, just put it in a sh file)
sh r.sh
Result:
INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: Component
Info{com.amap.auto.androidautomation.test/android.support.test.runner.AndroidJUn
}tRunner
INSTRUMENTATION_STATUS_CODE: -1
android.util.AndroidException: INSTRUMENTATION_FAILED: com.amap.auto.androidauto
mation.test/android.support.test.runner.AndroidJUnitRunner
at com.android.commands.am.Am.runInstrument(Am.java:1093)
at com.android.commands.am.Am.onRun(Am.java:371)
at com.android.internal.os.BaseCommand.run(BaseCommand.java:47)
at com.android.commands.am.Am.main(Am.java:100)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:251)
: not foundnload/r.sh[2]: exit

MEX fortran file using Gnumex and MinGW (g77)

There is a problem that I ran into recently. It used to be working fine as far as I remember but after a few week I am trying again to MEX a fortran 77 file in MATLAB but it is giving me a weird error.
Ok, I made the MEX options file using Gnumex which is named mexopts_f77.bat.
This is the command that I run in MATLAB:
mex -v -f C:\Omid\Other\Gnumex\mexopts_f77.bat -c sodex.f decsol.f
And this is the the error that I get:
-> Options file specified on command line
----------------------------------------------------------------
-> Options file = C:\Omid\Other\Gnumex\mexopts_f77.bat
MATLAB = C:\PROGRA~2\MATLAB\R2011b
-> COMPILER = gcc
-> Compiler flags:
COMPFLAGS = -c -DMATLAB_MEX_FILE -fcase-upper -fnounderscoring
OPTIMFLAGS = -O0
DEBUGFLAGS = -g
arguments =
Name switch = -o
-> Pre-linking commands =
-> LINKER = C:\PROGRA~2\MATLAB\R2011b\sys\perl\win32\bin\perl.exe C:\omid\other\gnumex\linkmex.pl
-> Link directives:
LINKFLAGS = -LC:\Omid\Other\Gnumex\libs
LINKDEBUGFLAGS = -g -Wl,--image-base,0x28000000\n
LINKFLAGSPOST =
Name directive = -o sodex.mexw32
File link directive =
Lib. link directive =
Rsp file indicator =
-> Resource Compiler = C:\PROGRA~2\MATLAB\R2011b\sys\perl\win32\bin\perl.exe C:\omid\other\gnumex\rccompile.pl -o mexversion.res
-> Resource Linker =
----------------------------------------------------------------
--> gcc -c -DMATLAB_MEX_FILE -fcase-upper -fno-underscoring -osodex.obj -O0 -DMX_COMPAT_32 sodex.f
gcc: error: unrecognized command line option '-fcase-upper'
C:\PROGRA~2\MATLAB\R2011B\BIN\MEX.PL: Error: Compile of 'sodex.f' failed.
I think the problem is with -fcase-upper option. I looked it up but could not find any information regrading that option for gcc.
Edit:
I manually changed gcc to g77 in my options file and was successful to create the object files but still getting an error in the final step where I try to link the object files to the main fortran script named vdpsodex.F and create the MEX file. As requested, I am including the option file:
#echo off
rem C:\Omid\Other\Gnumex\mexopts_f77.bat
rem Generated by gnumex.m script in C:\omid\other\gnumex
rem gnumex version: 2.06
rem Compile and link options used for building MEX etc files with
rem the Mingw/Cygwin tools. Options here are:
rem Gnumex, version 2.06
rem MinGW linking
rem Mex (*.dll) creation
rem Libraries regenerated now
rem Language: Fortran 77
rem Optimization level: -O0 (no optimization)
rem StorageVersion: 1.0
rem C++keyName: GNU C++
rem C++keyManufacturer: GNU
rem C++keyLanguage: C++
rem C++keyVersion:
rem C++keyFileName: GNUMEXOPTS.bat
rem Matlab version 7.13
rem
set GCCINSTALLDIR=C:\Omid\Other\MinGW\bin
set MATLAB=C:\PROGRA~2\MATLAB\R2011b
set GM_PERLPATH=C:\PROGRA~2\MATLAB\R2011b\sys\perl\win32\bin\perl.exe
set GM_UTIL_PATH=C:\omid\other\gnumex
set PATH=C:\Omid\Other\MinGW\bin;%PATH%
set PATH=%PATH%;C:\Cygwin\usr\local\gfortran\libexec\gcc\i686-pc-cygwin\4.3.0
set LIBRARY_PATH=C:\Omid\Other\MinGW\lib
set G95_LIBRARY_PATH=C:\Omid\Other\MinGW\lib
set MW_TARGET_ARCH=win32
rem
rem precompiled library directory and library files
set GM_QLIB_NAME=C:\Omid\Other\Gnumex\libs
rem
rem directory for .def-files
set GM_DEF_PATH=C:\Omid\Other\Gnumex\libs
rem
rem Type of file to compile (mex or engine)
set GM_MEXTYPE=mex
rem
rem Language for compilation
set GM_MEXLANG=f77
rem
rem File for exporting mexFunction symbol
set GM_MEXDEF=C:\Omid\Other\Gnumex\libs\fmex.def
rem
set GM_ADD_LIBS=-lg2c -lflibmx -lflibmex -lflibmat
rem
rem compiler options; add compiler flags to compflags as desired
set NAME_OBJECT=-o
rem ************ This is where I replaced gcc with g77 ************
set COMPILER=g77
rem ***************************************************************
set COMPFLAGS=-c -DMATLAB_MEX_FILE -fcase-upper -fno-underscoring
set OPTIMFLAGS=-O0
set DEBUGFLAGS=-g
rem
rem NB Library creation commands occur in linker scripts
rem but LIBLOC is provided for compatibility with
rem mex.getCompilerConfigurations
rem
rem Linker parameters
set LIBLOC=
set LINKER=%GM_PERLPATH% %GM_UTIL_PATH%\linkmex.pl
set LINKFLAGS=
set LINKOPTIMFLAGS=-s
set LINKDEBUGFLAGS=-g -Wl,--image-base,0x28000000\n
set LINKFLAGS= -LC:\Omid\Other\Gnumex\libs
set LINK_FILE=
set LINK_LIB=
set NAME_OUTPUT=-o %OUTDIR%%MEX_NAME%.mexw32
rem
rem Resource compiler parameters
set RC_COMPILER=%GM_PERLPATH% %GM_UTIL_PATH%\rccompile.pl -o %OUTDIR%mexversion.res
set RC_LINKER=
Now the above code does give me the object files but when I try to make the final MEX file using below command:
mex -v -f C:\Omid\Other\Gnumex\mexopts_f77.bat vdpsodex.F sodex.obj decsol.obj
it gives me the following error:
-> Options file specified on command line
----------------------------------------------------------------
-> Options file = C:\Omid\Other\Gnumex\mexopts_f77.bat
MATLAB = C:\PROGRA~2\MATLAB\R2011b
-> COMPILER = g77
-> Compiler flags:
COMPFLAGS = -c -DMATLAB_MEX_FILE -fcase-upper -fno-underscoring
OPTIMFLAGS = -O0
DEBUGFLAGS = -g
arguments =
Name switch = -o
-> Pre-linking commands =
-> LINKER = C:\PROGRA~2\MATLAB\R2011b\sys\perl\win32\bin\perl.exe C:\omid\other\gnumex\linkmex.pl
-> Link directives:
LINKFLAGS = -LC:\Omid\Other\Gnumex\libs
LINKDEBUGFLAGS = -g -Wl,--image-base,0x28000000\n
LINKFLAGSPOST =
Name directive = -o vdpsodex.mexw32
File link directive =
Lib. link directive =
Rsp file indicator =
-> Resource Compiler = C:\PROGRA~2\MATLAB\R2011b\sys\perl\win32\bin\perl.exe C:\omid\other\gnumex\rccompile.pl -o mexversion.res
-> Resource Linker =
----------------------------------------------------------------
--> g77 -c -DMATLAB_MEX_FILE -fcase-upper -fno-underscoring -oC:\Users\GHASEM~1\AppData\Local\Temp\2\mex_7FJjxb\vdpsodex.obj -O0 -DMX_COMPAT_32 vdpsodex.F
--> C:\PROGRA~2\MATLAB\R2011b\sys\perl\win32\bin\perl.exe C:\omid\other\gnumex\linkmex.pl -o vdpsodex.mexw32 -LC:\Omid\Other\Gnumex\libs -s C:\Users\GHASEM~1\AppData\Local\Temp\2\mex_7FJjxb\vdpsodex.obj sodex.obj decsol.obj
C:\Omid\Other\Gnumex\libs/flibmx.lib(ds00068.o):(.idata$7+0x0): undefined reference to `_head_C__Omid_Other_Gnumex_libs_flibmx_lib'
C:\Omid\Other\Gnumex\libs/flibmx.lib(ds00086.o):(.idata$7+0x0): undefined reference to `_head_C__Omid_Other_Gnumex_libs_flibmx_lib'
C:\Omid\Other\Gnumex\libs/flibmx.lib(ds00062.o):(.idata$7+0x0): undefined reference to `_head_C__Omid_Other_Gnumex_libs_flibmx_lib'
C:\Omid\Other\Gnumex\libs/flibmx.lib(ds00157.o):(.idata$7+0x0): undefined reference to `_head_C__Omid_Other_Gnumex_libs_flibmx_lib'
C:\Omid\Other\Gnumex\libs/flibmx.lib(ds00161.o):(.idata$7+0x0): undefined reference to `_head_C__Omid_Other_Gnumex_libs_flibmx_lib'
collect2: ld returned 1 exit status
link command: g77 -shared C:\Omid\Other\Gnumex\libs\fmex.def -o vdpsodex.mexw32 -LC:\Omid\Other\Gnumex\libs -s C:\Users\GHASEM~1\AppData\Local\Temp\2\mex_7FJjxb\vdpsodex.obj sodex.obj decsol.obj -lg2c -lflibmx -lflibmex -lflibmat
C:\PROGRA~2\MATLAB\R2011B\BIN\MEX.PL: Error: Link of 'vdpsodex.mexw32' failed.
emphasized textFinally, I was able to pin point the issue and I thought it might be beneficial to others who may be facing the same issue (or similar to this one) to share the answer. Let me just mention that it was looking strange to me at the first place because I had MEX'ed the exact same files using an option files created by Gnumex and had not problem at all. I just noticed that because I changed my MinGW build a while ago I was not able to MEX the same Fortran files anymore even though I re-created the options file (mexopts_f77.bat).
Anyways, to make the long story short I found this link very useful. Basically, it suggests downloading five packages and extracting them to the root directory of MinGw. Four of those links are still alive. One of them is dead but I found it by Googling the package name. What you see below is the updated links of the packages.
Last but not least, here is the solution if your g77 is not working with a Gnumex-made options file:
Download following packages:
binutils-2.19.1-mingw32-bin.tar.gz
gcc-core-3.4.5-20060117-3.tar.gz
gcc-g77-3.4.5-20060117-3.tar.gz
mingw-runtime-3.14.tar.gz
w32api-3.11.tar.gz
Extract them to your MinGW root directory, e.g. C:\MinGW
Re-make your options file by selecting Fortran 77 as compilation language, e.g. mexopt_f77.bat
MEX you Fortran script using following syntax.
mex -f [options-file] [fortran-file.f]
If you need to link some files to the main script then you have to compile them first to object files and then link them.
mex -f [options-file] -c [linkfile1.f] [linkfile2.f]
mex -f [options-file] [fortran-file.f] [linkfile1.obj] [linkfile2.obj]

Unable to verify checksum for exe

hi i have attached crash dump for an exe and symbols also.but i am getting this error:
Unable to verify checksum for abc.exe.
What would be the reason for this?
Unable to verify checksum is emitted when the checksum in the PE header isn't verifiable.
This can happen if the exe in question was compiled and linked without using /RELEASE linker option.
Normal project based compile linker sets this option. nmake or batch file based compilation can omit this switch and can lead to this output.
A simple hello world compiled and linked with and without /RELEASE linker option (PDB not generated for simpilicity and diffed to show the difference in timestamp and checksum). Loaded in WinDbg and checksum warning is generated only for the exe with no checksum in PE header.
simple hello world.cpp contents
testrelease:\>dir /b & type testrelease.cpp
testrelease.cpp
#include <stdio.h>
int main (void) {
printf("hello my relase\n");
return 0;
}
compiling without /RELEASE
testrelease:\>cl /nologo testrelease.cpp
testrelease.cpp
renaming the exe and compiling the same source with with /RELEASE
testrelease:\>ren testrelease.exe testrelease_norel.exe
testrelease:\>cl /nologo testrelease.cpp /link /release
testrelease.cpp
comparing both exes
testrelease:\>fc /b testrelease.exe testrelease_norel.exe
Comparing files testrelease.exe and TESTRELEASE_NOREL.EXE
000000E0: D6 CE
00000130: A3 00
00000131: 95 00
00000132: 01 00
analysing output of the comparison
testrelease:\>xxd -s +0x3c -l 1 testrelease.exe
000003c: d8 .
testrelease:\>xxd -s +0x3c -l 1 testrelease_norel.exe
000003c: d8 .
testrelease:\>echo d8 = NT_HEADER so e0 = TimeDateStamp and 130 = CheckSum
d8 = NT_HEADER so e0 = TimeDateStamp and 130 = CheckSum
loading both exes in windbg warning generated for only one exe without checksum
testrelease:\>cdb -c ".reload /f ; q" testrelease.exe
.*** ERROR: Module load completed but symbols could not be loaded for image00400
testrelease:\>cdb -c ".reload /f ; q" testrelease_norel.exe
.*** WARNING: Unable to verify checksum for image00400000
*** ERROR: Module load completed but symbols could not be loaded for image004000
no symbol header available error means the exe was compiled without debug information.
You can't do much about it unless you have a lot of expertise in recreating debug information from scratch.
Both the executables that are compiled above will generate the error because iIhave intentionally not created the debug information.
DBGHELP: image00400000 missing debug info. Searching for pdb anyway
DBGHELP: Can't use symbol server for image00400000.pdb - no header information available