<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Posts on xhd2015的博客</title>
    <link>https://blog.xhd2015.xyz/zh/posts/</link>
    <description>Recent content in Posts on xhd2015的博客</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>zh2</language>
    <lastBuildDate>Sun, 21 Apr 2024 19:31:34 +0800</lastBuildDate>
    <atom:link href="https://blog.xhd2015.xyz/zh/posts/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>xgo trace: 一个强大的Go堆栈可视化工具</title>
      <link>https://blog.xhd2015.xyz/zh/posts/xgo-trace_a-powerful-visualization-tool-in-go/</link>
      <pubDate>Sun, 21 Apr 2024 19:31:34 +0800</pubDate>
      <guid>https://blog.xhd2015.xyz/zh/posts/xgo-trace_a-powerful-visualization-tool-in-go/</guid>
      <description>概述 xgo提供了一系列工具，可以帮助Go开发者更快、更轻松地编写单元测试。&#xA;这些工具包括：&#xA;Trace Mock Trap 本文将介绍Trace工具。&#xA;如果你还不知道， xgo项目地址: https://github.com/xhd2015/xgo。&#xA;关于Trace工具 xgo中的Trace功能可用于可视化Go程序的执行过程。&#xA;在某些情况下，这可以替代调试器，减少查找错误所需的工作量。&#xA;问题背景 当我们开始接触一个新项目时，我们很难快速了解整个程序在底层做了什么。仅通过运行一些测试并观察结果是不够的。&#xA;xgo提供了Trace工具来解决这个问题。&#xA;为了展示Trace如何帮助我们快速理解代码，我将从几天前Reddit用户提出的一个随机项目开始，该项目可以在https://www.reddit.com/r/golang/s/RpEtEApIUj找到。&#xA;克隆仓库并运行一些测试 这里所选择的项目是pocketbase。&#xA;让我们按照下面的步骤开始：&#xA;克隆仓库 git clone https://github.com/pocketbase/pocketbase.git cd pocketbase 运行apis/backup_test.go的测试 go test -v -run TestBackupsList ./apis 输出：&#xA;=== RUN TestBackupsList === PAUSE TestBackupsList === CONT TestBackupsList === RUN TestBackupsList/unauthorized === RUN TestBackupsList/authorized_as_auth_record === RUN TestBackupsList/authorized_as_admin_(empty_list) === RUN TestBackupsList/authorized_as_admin --- PASS: TestBackupsList (0.83s) --- PASS: TestBackupsList/unauthorized (0.23s) --- PASS: TestBackupsList/authorized_as_auth_record (0.29s) --- PASS: TestBackupsList/authorized_as_admin_(empty_list) (0.</description>
    </item>
    <item>
      <title>xgo: 在go中使用-toolexec实现猴子补丁</title>
      <link>https://blog.xhd2015.xyz/zh/posts/xgo-monkey-patching-in-go-using-toolexec/</link>
      <pubDate>Thu, 04 Apr 2024 15:32:15 +0800</pubDate>
      <guid>https://blog.xhd2015.xyz/zh/posts/xgo-monkey-patching-in-go-using-toolexec/</guid>
      <description>概述 在这篇博客中，我将详细介绍 xgo 的实现细节。&#xA;如果你不知道，xgo 项目位于 https://github.com/xhd2015/xgo。&#xA;它的作用很简单，就是在每个 Go 函数的开头添加拦截器，从而引入了所谓的 Trap 概念，然后在此基础上引入了其他功能，比如 Mock、Patch 和 Trace。&#xA;什么是 Trap？ Trap 是插入到函数体开头的一段代码。以一个名为 greet 的函数为例：&#xA;func greet(s string) string { return &amp;#34;hello &amp;#34; + s } 经过xgo的处理后，编译器看到的代码将变为：&#xA;import &amp;#34;runtime&amp;#34; func greet(s string) (r0 string){ stop, post := runtime.__xgo_trap(greet, &amp;amp;s, &amp;amp;r0) if stop { return } defer post() return &amp;#34;hello &amp;#34; +s } 这两者的差异可以通过下面的图表来可视化：&#xA;如图所示，一旦函数被调用，它的控制流首先转移到 Trap，然后一系列拦截器将根据其目的检查当前调用是否应该被Mock、修改、记录或停止。&#xA;这个想法很简单，但也引发了一些问题：&#xA;编译器如何看到插桩后的代码？ import runtime 是什么？ 这两个问题反映了 xgo 的两个基本部分：编译器插桩和运行时插桩。&#xA;让我们先看看第一个问题。</description>
    </item>
    <item>
      <title>新的博客，新的开始</title>
      <link>https://blog.xhd2015.xyz/zh/posts/annoucing-my-new-blogs/</link>
      <pubDate>Mon, 01 Apr 2024 08:32:15 +0800</pubDate>
      <guid>https://blog.xhd2015.xyz/zh/posts/annoucing-my-new-blogs/</guid>
      <description>从今天开始，我将在这里发布我的博客。</description>
    </item>
    <item>
      <title>树莓派连接、启动和使用(raspberry pi)</title>
      <link>https://blog.xhd2015.xyz/zh/posts/raspberry-pi-connect-start-use/</link>
      <pubDate>Sat, 27 Jun 2020 08:58:13 +0800</pubDate>
      <guid>https://blog.xhd2015.xyz/zh/posts/raspberry-pi-connect-start-use/</guid>
      <description>硬件 树莓派3，Macos，树莓派TTL连接器(PL2303)&#xA;如下图所示&#xA;不好意思，贴错了&#xA;SD卡中刷入镜像(如果已经刷入则跳过) 首先下载raspbian最新版img，然后刷入sd卡中。&#xA;# 读卡器连接电脑, du -i /path/to/img -o /dev/usb-TODO 树莓派启动配置 sd卡刷完之后，就是一个完整的文件系统了。在电脑上，对该卡的BOOT分区进行修改。找到config.txt，增加下面两行：&#xA;boot_delay=5 dtoverlay=disable-bt cmdline将console改为/dev/ttyAMA0&#xA;console=ttyAMA0,115200 安装TTL转USB的驱动(Prolific 2303)&#xA;连接所需的驱动 macos和windows下载Prolific Serial-To-USB PL2303 Driver：PL2303 TTL串口驱动&#xA;参考 http://shumeipai.nxez.com/2015/09/06/mac-os-x-rpi-serial-connection.html 下载的zip文件会包含一个pdf文档连接教程和一个pkg安装文件。&#xA;连接 将树莓派接转接器，练到在macos上。树莓派建议使用外置电源。 通过ls /dev/tty.usbserial*找到真正的串口设备。&#xA;使用screen和minicom都可以(推荐screen，具有更好的输出展示，滚动等）， 使用screen连接&#xA;screen /dev/tty.usbserial 115200 使用minicom连接&#xA;minicom -b 1152300 -o -D /dev/tty.usbserial 可以连接树莓派的串口，可以看到树莓派的启动输出&#xA;通过Option+X退出minicom 通过Ctrl+a k退出screen&#xA;电源连接 如果树莓派以较低电压（低于5V/2.5A）启动，则可能启动失败（但也可能跳过）。&#xA;通过添加avoid_warning选项可以&#xA;选项链接： https://www.raspberrypi.org/documentation/configuration/config-txt/misc.md&#xA;说明&#xA;avoid_warnings The warning symbols can be disabled using this option, although this is not advised.</description>
    </item>
  </channel>
</rss>
