VSCode on MacとLaTeX Workshopでenv: perl: no such file or directory

症状

事前にHomebrewでVSCodeとMacTeX(とPerl)をインストールしていた

VSCode拡張機能LaTex Workshopをインストールして、適当な.texファイルを用意してcommand + option + Bでコンパイルしようとしたが以下のようなエラー

拡張機能のログを見てもこんな感じ

[01:32:43][Commander] BUILD command invoked.
[01:32:43][Commander] The document of the active editor: file://%WS1%/test.tex
[01:32:43][Commander] The languageId of the document: latex
[01:32:43][Manager] Current workspace folders: ["file://%WS1%"]
[01:32:43][Manager] Found root file from active editor: %WS1%/test.tex
[01:32:43][Manager] Keep using the same root file: %WS1%/test.tex
[01:32:43][Structure] Structure updated with 1 root sections for %WS1%/test.tex .
[01:32:43][Commander] Building root file: %WS1%/test.tex
[01:32:43][Builder] Build root file %WS1%/test.tex
[01:32:43][Builder] outDir: %WS1% .
[01:32:43][Builder] Preparing to run recipe: latexmk.
[01:32:43][Builder] Prepared 1 tools.
[01:32:43][Builder] Recipe step 1 The command is latexmk:[].
[01:32:43][Builder] env: {"PATH":"/Library/TeX/texbin"}
[01:32:43][Builder] root: %WS1%/test.tex
[01:32:43][Builder] cwd: %WS1%
[01:32:43][Builder] LaTeX build process spawned with PID 50552.
[01:32:43][Builder] Recipe returns with error code 127/null on PID 50552.
[01:32:43][Builder] Does the executable exist? $PATH: /Library/TeX/texbin, $Path: undefined, $SHELL: /bin/zsh
[01:32:43][Builder] env: perl: No such file or directory

[01:32:43][Builder] Cleaning auxiliary files and retrying build after toolchain error.
[01:32:43][Cleaner] Clean glob matched files {"globs":["*.aux","*.bbl","*.blg","*.idx","*.ind","*.lof","*.lot","*.out","*.toc","*.acn","*.acr","*.alg","*.glg","*.glo","*.gls","*.fls","*.log","*.fdb_latexmk","*.snm","*.synctex(busy)","*.synctex.gz(busy)","*.nav","*.vrb"],"outdir":"%WS1%"} .
[01:32:43][Cleaner] Ignore folder glob patterns with globstar:  .
[01:32:43][Builder] Recipe step 1 The command is latexmk:[].
[01:32:43][Builder] env: {"PATH":"/Library/TeX/texbin"}
[01:32:43][Builder] root: %WS1%/test.tex
[01:32:43][Builder] cwd: %WS1%
[01:32:43][Builder] LaTeX build process spawned with PID 50553.
[01:32:43][Builder] Recipe returns with error code 127/null on PID 50553.
[01:32:43][Builder] Does the executable exist? $PATH: /Library/TeX/texbin, $Path: undefined, $SHELL: /bin/zsh
[01:32:43][Builder] env: perl: No such file or directory

ちなみにターミナルからはlatexmkで普通にコンパイルできる

解決した方法

setting.jsonを見直してみる。

Before

//省略
"latex-workshop.latex.tools": [
        {
            "name": "latexmk",
            "command": "latexmk",
            "args": [],
            "env": {
                "PATH": "/Library/TeX/texbin"
            }
        },
//省略

PATHperlのパスを加えてみる(自分はHomebrewでインストールしていたので/opt/homebrew/bin)。

After

//省略
"latex-workshop.latex.tools": [
        {
            "name": "latexmk",
            "command": "latexmk",
            "args": [],
            "env": {
                "PATH": "/Library/TeX/texbin:/opt/homebrew/bin"
            }
        },
//省略

これでうまくいった。

参考

https://github.com/James-Yu/LaTeX-Workshop/issues/2390

Docker上でGDBとQEMU(ユーザモードエミュレーション)を接続してデバッグ

目標

筆者の実機(M1 Mac, AArch64)でx86_64のDockerコンテナを立ち上げ、その上でQEMUを用いてリモートデバッグをする

手順

x86_64なDockerコンテナを起動し、コンテナに入る

docker run -it --platform linux/amd64 ubuntu:latest

qemu-user-static gdb及びコンパイラ含め必要なツールをインストールする

apt update
apt install qemu-user-static gdb gcc vim

プログラムを書いてデバッグ情報付きでコンパイルする(a.outx86_64のバイナリ)

root@6fd1c6bc2337:/home# vim test.c
root@6fd1c6bc2337:/home# cat test.c
#include <stdio.h>

int main(void) {
    printf("Hello World\n");
    return 0;
}

root@6fd1c6bc2337:/home# gcc test.c -g -static
root@6fd1c6bc2337:/home# ./a.out
Hello World

qemu-x86_64-staticTCPの1234ポートを開く

qemu-x86_64-static -g 1234 a.out &

gdbでポートに接続しリモートデバッグを開始する

gdb -q -ex "target remote :1234" a.out

runコマンドが使えないことに注意(continueを使う)

root@6fd1c6bc2337:/home# gdb -q -ex "target remote :1234" a.out
Reading symbols from a.out...
Remote debugging using :1234
0x0000000000401650 in _start ()
(gdb) b main
Breakpoint 1 at 0x40177d: file test.c, line 4.
(gdb) run
The "remote" target does not support "run".  Try "help target" or "continue".
(gdb) c
Continuing.

Breakpoint 1, main () at test.c:4
4      printf("Hello World\n");
(gdb) n
Hello World
5      return 0;

コマンドライン引数ありの場合

コマンドラインを受け取るプログラムを書いてコンパイル

root@6fd1c6bc2337:/home# vim test.c
root@6fd1c6bc2337:/home# cat test.c
#include <stdio.h>

int main(int argc, char **argv) {
    for (int i = 0; i < argc; i++) {
        printf("%s\n", argv[i]);
    }

    return 0;
}

root@6fd1c6bc2337:/home# gcc test.c -g -static
root@6fd1c6bc2337:/home# ./a.out aaa iii
./a.out
aaa
iii

qemu-x86_64-staticで実行ファイル名の後に引数を書くようにすれば良い

qemu-x86_64-static -g 1234 a.out aaa iii &

リダイレクトについても同様

qemu-x86_64-static -g 1234 a.out aaa iii > output.txt &

なぜこの記事を書いたか

AArch64であるM1 Mac上のx86_64なDockerコンテナで普通にGDBを使おうとして以下のようになりできない

root@6fd1c6bc2337:/home# gdb a.out
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04) 12.1
Copyright (C) 2022 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-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from a.out...
(gdb) run
Starting program: /home/a.out
warning: Error disabling address space randomization: Operation not permitted
warning: Could not trace the inferior process.
warning: ptrace: Function not implemented
During startup program exited with code 127.

warning: ptrace: Function not implementedとあるようにGDB内で使われるシステムコールptrace()が削除されている(?)ようだ。 そこで今回その代替となるQEMUが提供するリモートデバッグ機能を利用するに至った。

参考になったサイト

DockerでユーザモードQEMUによるARMエミュレーション環境を構築する - ももいろテクノロジー

https://ughe.github.io/2018/08/14/qemu-gdb-integration

テスト

初めてなので、色々試してみる

  • 文字のスタイル
  • 箇条書き
  • リンク
  • 引用
  • ぴくちゃあ
  • 商品紹介
  • Gist

 

文字のスタイル

太字

斜体

取消

下線

箇条書き

  • あいう
  • ABC
  • αβγ
  1. uno
  2. dos
  3. tres

*1

リンク

google.com

引用

ああ:あああああああああああああぁあ

https://ja.uncyclopedia.info/wiki/%E3%81%82%E3%81%82%E3%81%82%E3%81%82%E3%81%82%E3%81%82%E3%81%82%E3%81%82%E3%81%82!

 

ぴくちゃあ

おしゃん

byばりぐっどくん

商品紹介

おすすめ❗️

 

Gist

gist7161e36dcdb716a6b114d1a0303f3a9a

*1:えすぱにょ〜る

続きを読む