Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions 000-template/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
all:
clang++ -std=c++17 -g main.cpp -o main

clean:
rm -rf main *.dSYM
33 changes: 33 additions & 0 deletions 000-template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# UB - Uninitialized Local Variable

## TL;DR

- In the C++ on Sea keynote, Herb Sutter showed some code with undefined behavior in C++
- Turns out that C++ can have UB when reading a local variable that is uninitalized
- I was confused by this and decided to investigate further by looking into the assembly code
- The point of this investigation is to learn what's happening under the hood in the compiler
- (Note that this issue will be fixed by default in C++ 26 which is great!)

## Video Overview

- Start by recreating the C++ code from Herb's slide
- Go over the C++ code and explain what we expect to happen vs what actually happens
- Run the code to ensure the undefined behavior (as expected :P)
- Turn on `ftrivial-auto-var-init=zero` flag and confirm that UB is NOT there anymore
- This flag basically ensures that
- These flags are default to true in C++ 26
- So we can expect them to be gone with no code changes in the future
- Investigate the assembly for UB code
- Investigate the assembly diff for non-UB code

## Helpful LLDB Commands

## Sample Assembly Code

## Titles

## References

- Herb Sutter's Keynote at C++ on Sea - https://www.youtube.com/watch?v=kKbT0Vg3ISw
- Herb Sutter's Website - https://herbsutter.com/
- ChatGPT and Gemini
9 changes: 9 additions & 0 deletions 000-template/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <iostream>

int main() {
int a = 1;
int b = 2;
int c = 5;
std::cout << "sum -> " << a + b + c << std::endl;
return 0;
}
10 changes: 5 additions & 5 deletions 010-ub-for-uninitialized-var/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ main`f1:
# Process 4758 stopped
```

## Titles

- How C++ 26 Fixes Undefined Behavior for Unintialized Local Variables
- How C++ Prevents Undefined Behavior for Uninitialized Local Variables

## References

- Herb Sutter's Keynote at C++ on Sea - https://www.youtube.com/watch?v=kKbT0Vg3ISw
- Herb Sutter's Website - https://herbsutter.com/
- ChatGPT and Gemini (if these count)

## Title

- How C++ 26 Fixes Undefined Behavior for Unintialized Local Variables
- How C++ Prevents Undefined Behavior for Uninitialized Local Variables
Binary file removed 010-ub-for-uninitialized-var/main
Binary file not shown.
20 changes: 0 additions & 20 deletions 010-ub-for-uninitialized-var/main.dSYM/Contents/Info.plist

This file was deleted.

Binary file not shown.

This file was deleted.

5 changes: 5 additions & 0 deletions 011-lldb-init-settings/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
all:
clang++ -std=c++17 -g main.cpp -o main

clean:
rm -rf main *.dSYM
44 changes: 44 additions & 0 deletions 011-lldb-init-settings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# LLDB Init Settings

## TL;DR

- It is tedious to set up LLDB commands every time you compile C++ code (or re-open LLDB)
- For example, you may need to run these 2 commands on restart (every time)
- `b main` (break point at main)
- `target stop-hook add -o "disassemble"` (show assembly)
- You can avoid this repetitive process by adding creating the `~/.lldbinit` file

## Video Overview

- Go over sample C++ code
- Show how to run LLDB by using `-g` compiler flag
- Show the need for using `b main` and `target stop-hook add -o "disassemble"`
- Change code, recompile, re-run LLDB, and notice that the settings are lost
- Show how setting up the `~/.lldbinit` file solves this problem

## LLDB Init Settings

- Add this to `~/.lldbinit` file

```bash
# file -> ~/.lldbinit

# break point at main
breakpoint set --name main

# show assembly by default
target stop-hook add -o "disassemble"

# use this instead if you want to see 10 lines of assembly at program counter
# target stop-hook add -o "disassemble --pc --count 10"
```

## Titles

- How to Improve LLDB Debugger Developer Experience?
- How to Improve LLDB (gdb) Developer Experience for Debugging?
- How to Improve LLDB (GDB) Developer Experience with Custom Settings

## References

- ChatGPT
9 changes: 9 additions & 0 deletions 011-lldb-init-settings/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <cstdio>

int main() {
int a = 1;
int b = 5;
int c = 6;
printf("sum -> %d\n", a + b);
return 0;
}