]> git.feebdaed.xyz Git - linuxyz.git/commitdiff
material ready
authorseantywork <seantywork@gmail.com>
Thu, 17 Apr 2025 10:41:05 +0000 (10:41 +0000)
committerseantywork <seantywork@gmail.com>
Thu, 17 Apr 2025 10:41:05 +0000 (10:41 +0000)
0xgo/fault/2504-03.xyz.md
0xgo/fault/main.go
fault/2504-03.xyz.md

index ad5c5d8256183421ae654bd4719c83ff0bb888d2..1513a9415e086d3065e83580e173f4b5332c2479 100644 (file)
  82 
 
 
+```
+
+#
+
+```shell
+
+    PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND                   
+  13784 seantyw+  20   0 1226856   4568   1536 S 107.3   0.1   0:22.65 test.out                  
+   2903 seantyw+  20   0   11.1g  75580  45056 S   9.3   0.9   0:04.94 node                      
+   2797 seantyw+  20   0   11.3g 102748  47872 R   6.0   1.3   0:05.74 node                      
+   3718 seantyw+  20   0   31.3g 142516  55296 S   3.3   1.8   0:10.09 node          
+```
+
+#
+
+```shell
+$ ls
+2504-03.xyz.md  go.prof  main.go  Makefile  test.out
+
+
+$ sudo apt update && sudo apt install graphviz
+
+
+$ go tool pprof -png go.prof
+Generating report in profile001.png
+```
+
+#
+
+```shell
+94 type NullStruct struct {
+95         Value int
+96         Field *NullStruct
+97 }
+
+
+121 
+122                 null := NullStruct{}
+123 
+124                 fmt.Printf("val: %d\n", null.Field.Value)
+125 
+
+```
+
+# 
+
+```shell
+$ ./test.out 2
+panic: runtime error: invalid memory address or nil pointer dereference
+[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4b7593]
+
+goroutine 1 [running]:
+main.main()
+        /home/seantywork/hack/linux/linuxyz/0xgo/fault/main.go:124 +0xb3
+
 ```
\ No newline at end of file
index b5ed4098c5902b680288448e38c494e27a2c8506..092bcd06a3837cd069664ab53a83bf4d355bc3de 100644 (file)
@@ -91,15 +91,37 @@ func profiler(waits int) {
 
 }
 
+type NullStruct struct {
+       Value int
+       Field *NullStruct
+}
+
 func main() {
 
-       go threadFunc()
+       argc := len(os.Args)
+
+       if argc != 2 {
+               fmt.Printf("feed case\n")
+               os.Exit(-1)
+       }
 
-       go profiler(10)
+       if os.Args[1] == "1" {
 
-       for {
+               go threadFunc()
+
+               go profiler(10)
+
+               for {
+
+                       time.Sleep(time.Millisecond * 1000)
+
+               }
+
+       } else if os.Args[1] == "2" {
+
+               null := NullStruct{}
 
-               time.Sleep(time.Millisecond * 1000)
+               fmt.Printf("val: %d\n", null.Field.Value)
 
        }
 
index c90a9030b5ce143cc47e3057d86b9f50210eb8b7..687c2babdeae9ab362bda11acb3af90402ef6968 100644 (file)
@@ -34,7 +34,7 @@ sudo top -H -p 45742
 ```
 
 
-# 02 
+# 
 
 
 ```shell
@@ -69,7 +69,7 @@ sudo top -H -p 45742
 
 
 
-# 03
+# 
 
 ```shell
 (gdb) thread 2
@@ -78,7 +78,7 @@ sudo top -H -p 45742
 43                  val = val ^ 1;
 ```
 
-# 04
+# 
 ```shell
 (gdb) step
 35                  if(nanosleep(&request , &remaing) < 0){
@@ -113,7 +113,7 @@ thread_func (p=0x3c75ade0) at main.c:43
 
 ```
 
-# 05
+# 
 
 ```shell
 
@@ -135,7 +135,7 @@ thread_func (p=0x3c75ade0) at main.c:43
 ```
 
 
-# 05
+# 
 
 ```shell
 
@@ -148,7 +148,7 @@ Num     Type           Disp Enb Address            What
 
 ```
 
-# 06
+#
 
 ```shell
 
@@ -299,15 +299,15 @@ $1 = 5
 # 
 
 ```shell
-thy@thy-Z370-HD3:~/hack/linux/linuxyz/fault$ ulimit -c
+$ ulimit -c
 0
-thy@thy-Z370-HD3:~/hack/linux/linuxyz/fault$ ulimit -c unlimited
-thy@thy-Z370-HD3:~/hack/linux/linuxyz/fault$ ulimit -c
+$ ulimit -c unlimited
+$ ulimit -c
 unlimited
 ```
 #
 ```shell
-thy@thy-Z370-HD3:~/hack/linux/linuxyz/fault$ ./test.out 2
+$ ./test.out 2
 Segmentation fault (core dumped)
 
 ```
@@ -316,7 +316,7 @@ Segmentation fault (core dumped)
 # 
 
 ```shell
-thy@thy-Z370-HD3:~/hack/linux/linuxyz/fault$ ls
+$ ls
 2504-03.xyz.md  core  main.c  Makefile  test.out
 
 ```