Author: Chris Lattner
PlantUML is a really awesome way to create diagrams by writing code instead of drawing and dragging visual elements. Markdown is a really nice documentation tool.
Here's how I combine the two, to create docs with embedded diagrams.
Get the command-line PlantUML from the download page or your relevant package manager.
#!/usr/bin/env bash | |
set -e | |
CONTEXT="$1" | |
if [[ -z ${CONTEXT} ]]; then | |
echo "Usage: $0 KUBE-CONTEXT" | |
exit 1 | |
fi |
#include <iostream> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <linux/ioctl.h> | |
#include <linux/types.h> | |
#include <linux/v4l2-common.h> | |
#include <linux/v4l2-controls.h> | |
#include <linux/videodev2.h> | |
#include <fcntl.h> | |
#include <unistd.h> |
section .text | |
global _start | |
_start: | |
mov eax, 2 ; SYS_FORK Op Code | |
int 0x80 | |
cmp eax, 0 ;If the return value is 0, we are in the child process | |
jz child | |
parent: | |
mov edx, len ;Move msg length to edx |
[alias] | |
wip = for-each-ref --sort='authordate:iso8601' --format=' %(color:green)%(authordate:relative)%09%(color:white)%(refname:short)' refs/heads | |
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"log" | |
"net" | |
"os" | |
"time" | |
) |
// -- 调用者(操作系统内核) | |
extern "sbicall" fn sbi_call(param: [usize; 6], a6: usize, a7: usize) -> (usize, usize); | |
// 最后两个参数必须是两个usize类型,a6: usize和a7: usize | |
// 除了最后两个参数,前面的参数必须是usize、[usize; N]或(usize, usize, ..)类型 | |
// 依次会被填写到a0, a1, ..., a5寄存器中。 | |
// 返回值可以是(usize, usize), [usize; 2]或者SbiRet(包含两个usize的结构体) | |
fn kernel() { |
On an embedded project, I recently had to debug a crash where the root cause was a division by zero. The offending code in question reduced to something like function foo()
presented here.
To validate that it actually was a division by zero problem, I added the if block that printed "GOTCHA". After this change, I saw that the processor status register (CFSR) had the UNDEFINST
bit set instead of the exepected DIVBYZERO
bit. What?
Using godbolt we can see the compiler emitting an instruction 0xdeff
in main... with no other code (suggesting that the compiler realized that the code will not work and simply stopped -- without warning, I might add).