VsCode debug cpp


Using VsCode to debug c++ project on WSL with intellisense and breakpoint support.
Folder: $MY_ROOT = /mnt/s/Rio/proj/linux/IdeVscode has dbg/ for output files, make/ for source and config files.


1.Installation: since I am running on WS2, I installed extension “Remote – WSL 0.51.4”. Then I installed extension “C/C++ 1.1.3”
Entry point is $MY_ROOT/ide.code-workspace, “path”: “/mnt/s/rio/proj/linux/IdeVscode/make” which is ${workspaceFolder}
2. launch vscode, and open workspace ide.code-workspace
${workspaceFolder} has: head.h main.cpp as test source files and .vscode, which has the key files explained below.
3. build the project to generate executable file $MY_ROOT/dbg/elfVscode click pressing Ctrl-Shift-B, or palette: Tasks Run build task
4. set breakpoint by clicking the left area of source code file.
5. run: Ctrl-Shift-B or: click the Run tab at very left, then the triangle button at top. program stops at breakpoint and variables can be inspected.
6. intellisense: right click testDef and choose “go to definition”, it detects ifdefine and go to the right location.

${workspaceFolder}/.vscode has the key config files:
launch.json: “program” tells which executable to launch
tasks.json: how to build the executable, like “command” tells about /bin/g++ , “args” tells about main.cpp and the ifdef
c_cpp_properties.json: have similar info as tasks.json, but used by intellisense instead of build task.
It seems the new extension, “ms-vscode.makefile-tools”, can cover both tasks.json and c_cpp_properties.json, but it’s still in preview.
download: http://riowing.net/p/wp/IdeVsCode.zip
screenshot: scrIde.jpg

POSIX compliant


POSIX-certified OS are not the most popular: macOS, EulerOS from Huawei, and they paid a fee
POSIX-compliant is Linux, but they didn’t pay a fee, therefore not certified
WSL: supposed to behave the same way as native linux, compatible at ELF binary level
Cygwin: linux program to be recompiled, compatible at source code level
MinGW = mingw32, Mingw-w64: reduced Cygwin feature set without dependency on Cygwin DLLs
UnxUtils: just executables like chmod.exe, not for building executables
Android: further away from the standard since it has bionic instead of glibc.
POSIX is about OS support for writing executables: c API, commandline tools, shell launguage, file system.

domain settings


Settings of my domain riowing.net from domains.google.com, query done by “nslookup.exe -type=?? …” .


-type=ns: riowing.net output name server name: “Non-authoritative answer:” “nameserver = ns-cloud-c1.googledomains.com”
-type=a riowing.net output: Non-authoritative answer: Address: 54.176.162.20
-type=a riowing.net output: ns-cloud-c1.googledomains.com Address: 54.176.162.20 without the word “Non-authoritative answer”
-type=AAAA riowing.net output IPv6: Address: 2600:1f1c:bc5:50aa::8
-type=mx riowing.net output mail server: MX preference = 10, mail exchanger = riowing.net, output: my email server name
-type=CNAME ftp.riowing.net output: Addresses: 2600:1f1c:bc5:50aa::8 54.176.162.20 Aliases: ftp.riowing.net
since I have CNAME record pointing ftp to .
-type=PTR riowing.net output: name = myptr.riowing.net. myptr.riowing.net is what I set up in google domains.
This is useless since Pointer Record is for looking for name based on IP address like below.
-type=PTR 54.176.162.20 output: “20.162.176.54.in-addr.arpa name = riowing.net” instead of myptr.riowing.net.
The reason is that the server resolving the IP address is setup by AWS, instead of google domains
If I query with “-type=PTR 54.176.162.20 ns-cloud-c1.googledomains.com output: UnKnown can’t find 54.176.162.20: Query refused
I cannot set up PTR since domains.google.com is not the authoritative server for IP address.
-type=ANY riowing.net returens all info like AAAA Ipv4 M PTR nameserver including LDAP server name.
-type=SRV _ldap._tcp.riowing.net _ldap._tcp is like keyword meaning ldap over tcp. output:
_ldap._tcp.riowing.net SRV service location: port = 389 svr hostname = ldap.riowing.net

Seccomp Test


A quick test on seccomp, by which a process gives up some syscall so that the damage can be limited in case of process out of control.
In this test, when SYS_execve syscall is made, the kernel terminates the process with message “Bad system call”.
Steps:

  1. install headers and libraries: sudo apt install libseccomp-dev
  2. source code:
    seccomp_load() to actives the secomp jail
  3. seccomp_rule_add(ctx, SCMP_ACT_KILL, SCMP_SYS(execve), 0);
    syscall(SYS_execve …) causes termination
  4. to build and run
    $ …/src$ make && ../dbg/elf
    Download: http://riowing.net/p/wp/seccomp.zip