Monthly Archives: July 2023

C++ Debugging with gdb

$ readelf -S <executable>
[...]
  [29] .debug_aranges    PROGBITS         0000000000000000  0001e5dd
       00000000000025d0  0000000000000000           0     0     1
  [30] .debug_info       PROGBITS         0000000000000000  00020bad
       00000000000fe146  0000000000000000           0     0     1
  [31] .debug_abbrev     PROGBITS         0000000000000000  0011ecf3
       00000000000078ba  0000000000000000           0     0     1
  [32] .debug_line       PROGBITS         0000000000000000  001265ad
       0000000000009e15  0000000000000000           0     0     1
  [33] .debug_str        PROGBITS         0000000000000000  001303c2
       00000000000461b1  0000000000000001  MS       0     0     1
  [34] .debug_ranges     PROGBITS         0000000000000000  00176573
       00000000000027d0  0000000000000000           0     0     1
[...]

C++ const

Const Correctness / C vs. C++ Differences
error: passing xxx as ‘this’ argument of xxx discards qualifiers

you’re calling a non-const member function on const object which is not allowed because non-const member functions make NO PROMISE not to modify the object

What is the meaning of ‘const’ at the end of a member function declaration?
declaring a const instance of a class

error: passing xxx as 'this' argument of xxx discards qualifiers
error: passing ‘const Foo’ as ‘this’ argument of ‘void Foo::bar()’ discards qualifiers [-fpermissive]
class Foo {
  public:
    Foo() {};
    virtual ~Foo() {};
    
    // must be const:
    // void bar() const {};
    void bar() {};
};

int
main(int argc, char *argv[])
{
  const Foo foo;

  foo.bar();

  return 0;
}

C++ chrono

C++ Performance Timer, uses the C++20 language standard

cppreference.com

Date and time utilities
std::chrono::duration
std::formatter
std::put_time

cplusplus.com

Time library
std::chrono::duration

C++ Cross-Platform High-Resolution Timer
chrono_literals is not a namespace-name
How to get duration, as int milli’s and float seconds from ?
Outputting Date and Time in C++ using std::chrono
Print current system time in nanoseconds using c++ chrono
How to convert std::chrono::time_point to string


Old-Style C

Print current system time in nanoseconds using c++ chrono
what is gettimeofday() equivalent in c++11

struct timeval now;

// seconds and nanoseconds
gettimeofday(&now, NULL);
const std::tm *localTime = std::localtime((time_t *) &now.tv_sec);

// only in seconds
//std::time_t now = std::time(nullptr);
//const std::tm *localTime = std::localtime(&now);

// GCC < 5.0
char dateTime[] = "00.00.00 00:00:00.";
char millis [] = "000";
strftime(dateTime, sizeof(dateTime), "%d.%m.%y %H:%M:%S.", localTime);
snprintf(millis, sizeof(millis), "%03li", now.tv_usec/1000 );

cout << dateTime << millis << " | ";


date


SIGSEGV

$ gdb build/bin/PerfTest
GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.el7
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /app/dev/andreas/build/bin/PerfTest...done.
(gdb) r
Starting program: /app/dev/andreas/build/bin/PerfTest
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff6b316a3 in std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /lib64/libstdc++.so.6
Missing separate debuginfos, use: debuginfo-install glibc-2.17-326.el7_9.x86_64 libgcc-4.8.5-44.el7.x86_64 libstdc++-4.8.5-44.el7.x86_64
(gdb) bt
#0  0x00007ffff6b316a3 in std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /lib64/libstdc++.so.6
#1  0x0000000000401751 in app (trx=0x7fffffffe260) at /app/dev/andreas/PerfTest/main.cpp:47
#2  0x00000000004018d1 in main (argc=1, argv=0x7fffffffe398) at /app/dev/andreas/PerfTest/main.cpp:104

C++ map

Fun with printing tables with std::format and C++20
Const collection of unique_ptr, options and design choices

C++ Map Explained with Examples
Map in C++ Standard Template Library (STL)

How to use range-based for() loop with std::map?
std::map::at
How to find if a given key exists in a C++ std::map
C++: std::map throws an out_of_range exception

At Map C++
C++ map at()

// 
for (const auto& [key, value]: myMap) {
    std::cout << key << " has value " << value << std::endl;
}

Structured binding declaration
A brief introduction to C++ structured binding
Structured binding in C++

for (const auto& kv : myMap) {
    std::cout << kv.first << " has value " << kv.second << std::endl;
}

Range-based for loop
Range-based for loop in C++
Range-based for Statement (C++)

Oracle


/*************************************************************************************
 * sqlplus: no TNS_ADMIN => error
 */

$ ${ORACLE_HOME}/bin/sqlplus -L <user>@<servicename>
SQL*Plus: Release 19.0.0.0.0 - Production on Mon Jul 10 19:08:27 2023
Version 19.13.0.0.0
Copyright (c) 1982, 2021, Oracle.  All rights reserved.

ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified

SP2-0751: Unable to connect to Oracle.  Exiting SQL*Plus

/*************************************************************************************
 * sqlplus: with TNS_ADMIN, TCPS using sqlnet.ora/wallet => error, wallet not accessible (permission denied)
 */

$ TNS_ADMIN=/app/tns ${ORACLE_HOME}/bin/sqlplus -L <user>@<servicename>
SQL*Plus: Release 19.0.0.0.0 - Production on Mon Jul 10 19:08:56 2023
Version 19.13.0.0.0
Copyright (c) 1982, 2021, Oracle.  All rights reserved.

ERROR:
ORA-28759: failure to open file

SP2-0751: Unable to connect to Oracle.  Exiting SQL*Plus

/*************************************************************************************
 * tnsping: with TNS_ADMIN, TCPS using sqlnet.ora/wallet => error, wallet not accessible (permission denied)
 */
$ TNS_ADMIN=/app/tns ${ORACLE_HOME}/bin/tnsping <servicename>
TNS Ping Utility for Linux: Version 19.0.0.0.0 - Production on 11-JUL-2023 08:18:34
Copyright (c) 1997, 2021, Oracle.  All rights reserved.

Used parameter files:
/app/tns/sqlnet.ora

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION_LIST= (LOAD_BALANCE=off) (FAILOVER=off) (DESCRIPTION= (CONNECT_TIMEOUT=5) (TRANSPORT_CONNECT_TIMEOUT=3) (RETRY_COUNT=3) (ADDRESS_LIST= (LOAD_BALANCE=on) (ADDRESS= (PROTOCOL=TCPS) (HOST=<hostname>) (PORT=1522))) (CONNECT_DATA= (SERVICE_NAME=<servicename>))))

TNS-12560: TNS:protocol adapter error

/*************************************************************************************
 * tnsping: with TNS_ADMIN, TCP => ok
 */
$ TNS_ADMIN=/app/tns ${ORACLE_HOME}/bin/tnsping <servicename>

TNS Ping Utility for Linux: Version 19.0.0.0.0 - Production on 11-JUL-2023 09:52:39

Copyright (c) 1997, 2021, Oracle.  All rights reserved.

Used parameter files:
/app/tns/sqlnet.ora

Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION_LIST= (LOAD_BALANCE=off) (FAILOVER=off) (DESCRIPTION= (CONNECT_TIMEOUT=5) (TRANSPORT_CONNECT_TIMEOUT=3) (RETRY_COUNT=3) (ADDRESS_LIST= (LOAD_BALANCE=o) (ADDRESS= (PROTOCOL=TCP) (HOST=<hostname>) (PORT=1521))) (CONNECT_DATA= (SERVICE_NAME=<servicename>))))

OK (0 msec)

/*************************************************************************************
 * sqlplus: with TNS_ADMIN, TCP => ok
 */
$ TNS_ADMIN=/app/tns ${ORACLE_HOME}/bin/sqlplus <user>@<servicename>

SQL*Plus: Release 19.0.0.0.0 - Production on Tue Jul 11 09:52:48 2023
Version 19.13.0.0.0

Copyright (c) 1982, 2021, Oracle.  All rights reserved.

Enter password:
Last Successful login time: Tue Jul 11 2023 07:18:44 +02:00

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.18.0.0.0

SQL> exit
NLS_LANG=American_America.WE8ISO8859P1
NLS_LANG=American_America.UTF8

GSS / GSSAPI / RFC 4462

RFC 4462 Generic Security Service Application Program Interface (GSS-API) Authentication and Key Exchange for the Secure Shell (SSH) Protocol
The Kerberos V5 (“GSSAPI”) Simple Authentication and Security Layer (SASL) Mechanism

RFC 2743, Generic Security Service Application Program Interface Version 2, Update 1
RFC 2744, Generic Security Service API Version 2 : C-bindings
RFC 7546, Structure of the Generic Security Service (GSS) Negotiation Loop

SS-API Key Exchange with SHA2

Developing with GSSAPI

GssApiProblem
Dell Unity: Weak SSH key exchange algorithm is reported by third-party Vulnerability scanning software on Unity code 5.1.X (User Correctable)
GSSAPI im RZ der TUHH
SSPI/Kerberos Interoperability with GSSAPI
Chapter 1 The GSS-API: An Overview
Steps for setting up user authentication with GSS-API (Kerberos)

Wikipedia

GSSAPI (de)
Generic Security Service Application Program Interface (GSSAPI) (en)