[Meng new] Mac OS install Emacs + GDB development environment

[Meng new] Mac OS install Emacs + GDB development environment

In order to be consistent with the programming environment of the laboratory computer, the process of installing Emacs and gdb on the Mac was started. Repeated many times, combined with the experience of many seniors, here is a record of my installation process, for backup.

Version Information

  • Mac OS High Sierra , version 10.13.6 (Apple's small icon About this Mac option found)
  • Emacs 26.1 (Terminal 指令:emacs --version)
  • GNU gdb (GDB) 8.0.1 (Terminal 指令:gdb --version)

Download and install Emacs

Use Homebrew to install the latest version, the command in Terminal:

brew install emacs --with-cocoa

Configure the .emacs file

Because it is new, try to use the emacs configuration of the laboratory, which is consistent with your Mac.
The official configuration instructions are here: https://www.emacswiki.org/emacs/InitFile
Since the original .emacs file cannot be found, a new file init file is created in emacs with reference to the official instructions, and the configuration file is posted Inside, effective buffer. But the consequence is that the buffer will take effect again every time emacs is re-used. Try the following operations, that is, find the .emacs file and add personal configuration to it, and take effect, so the configuration is successful 1 .
The following steps refer to Note 1. The method is to first modify a certain setting of emacs, and find the .emacs file and modify it. The article takes the flashing icon as an example:

  1. Open emacs, enter Mx customize to enter the user setting interface (mac's meta key, which is M, is esc)
  2. Find the Environment link below and enter, continue to find Frames and enter
  3. Find Cursor in the subgroups below and enter
  4. Find Blink Cursor Mode, click the triangle in front, click Toggle to change the mode to off
  5. Click state and press 1 again to save the settings
  6. Cx Cf (find or create file) ~ / .emacs Enter to find and open the configuration file
  7. Fill in the configuration file. The configuration file is written using lisp, generally you can find it out of the box. The ";" symbol is a note. Here is mainly to set the background color and some shortcut keys. I commented out a setting here because it was not successful when it took effect. The more important one is that the shortcut key Cx Cu opens a shell in emacs, so that the compilation and running of the program can be carried out in emacs, which is more convenient. In addition, the line number display 2 can also be turned on , which is very convenient when debugging.
	 '(default ((t (:background "#B4EEB4")))))
(global-font-lock-mode t)
(global-set-key "\C-xs" 'save-buffer)
(global-set-key "\C-xv" 'quoted-insert)
(global-set-key "\C-xg" 'goto-line)
(global-set-key "\C-xf" 'search-forward)
(global-set-key "\C-xc" 'compile)
(global-set-key "\C-xt" 'text-mode)
(global-set-key "\C-xr" 'replace-string)
(global-set-key "\C-xa" 'repeat-complex-command)
(global-set-key "\C-xm" 'manual-entry)
(global-set-key "\C-xw" 'what-line)
(global-set-key "\C-x\C-u" 'shell)
(global-set-key "\C-x0" 'overwrite-mode)
(global-set-key "\C-x\C-r" 'toggle-read-only)
(global-set-key "\C-t" 'kill-word)
(global-set-key "\C-p" 'previous-line)
(global-set-key "\C-u" 'backward-word)
(global-set-key "\C-o" 'forward-word)
(global-set-key "\C-h" 'backward-delete-char-untabify)
(global-set-key "\C-x\C-m" 'not-modified)
(setq make-backup-files 'nil)
(setq default-major-mode 'text-mode)
(setq text-mode-hook 'turn-on-auto-fill)
;;(set-default-font "-misc-fixed-medium-r-normal--15-140-*-*-c-*-*-1")

;(require 'font-lock)
;(add-hook 'c-mode-hook 'turn-on-font-lock)
;(add-hook 'c++-mode-hook 'turn-on-font-lock)

;;line-number-mode
(global-linum-mode t)
  1. Finally, the configuration file of Mx eval-buffer takes effect.

Install gdb (Terminal)

  1. First determine if there is gdb 3 on the Mac, and I do n’t have it on my computer. Refer to the link method and update the homebrew software library first:

    brew update
    
  2. Make sure gdb is in the software library:

    brew search gdb
    

    The display is as follows:Insert picture description here

  3. Install gdb:

    brew install gdb
    

Certificate signing

If you use the gdb command directly, the following error will appear:

please check gdb is codesigned - see taskgated(8)

At this point, you need to create a certificate for gdb with a codesigned method.
There are many online certificate created on a Mac gdb tutorial Raiders 4 . I wrote down according to the problems and steps I encountered, mainly referring to the blog post of note [4].

  1. Open the Keychain Access application, click keychain access in the toolbar, select the third item, Certificate Assistant , and then select the second item, Create a certificate ... , and then name it. The certificate type is Code Signing . Let me override default also be checked .
  1. Certificates are often filled in as needed.
  1. Continue all the way to the specified certificate location. Here, you should select System ( System ). Since the subsequent creation is unsuccessful, directly select the default Login , click Create , and drag it into the System column after creation .
  1. In Keychain Access the System found just created a good certificate, double-click, and to bar codesign choose to always trust the trust column.
  1. Close the taskgated process:
    find the Activity Monitor application, search for the taskgated process under the CPU column , and quit .

  2. Effective certificate, statement effective certificate, statement:

    codesign -s gdb_cert /usr/local/bin/gdb
    

    -s is followed by the certificate name, followed by the address of gdb. You can also use $ (which gdb) instead.
    No output means the declaration is successful.

    In the future, if there is a problem with verifying the certificate, you can first use the following command to see if the certificate is successful:

    codesign -v  /usr/local/bin/gdb
    

    There is also no output.

    Note: In other methods, the taskgated process will be killed again here, because it restarts automatically afterwards. But when I went to the activity monitor to find the process in this step, I found that there was no taskgated process, so I restarted the computer.

Downgrade GDB

At this point, I tried to run gdb, but I got the following error when running the program:

During startup program terminated with signal SIGTRAP, 
Trace/breakpoint trap.

After finding that the high version of gdb is incompatible with the high version of Mac OS, I tried to downgrade the GDB version from 5 to 8.0.1:

brew unlink gdb
brew install https://raw.githubusercontent.com/Homebrew
/homebrew-core/9ec9fb27a33698fc7636afce5c1c16787e9ce3f3/Formula/gdb.rb

Other errors

Due to various errors in my entire installation process, some of the order can not be remembered, the last one should be the last problem encountered, about the SIP protection mechanism.
If there are other situations since then, add problems and solutions here.

  1. After restarting and running GDB, the following error appears when running the program:

    During startup program terminated with signal ?, Unknown signal.
    

    This is SIP (System Integrity Protection) Problem 6 The higher version of the system protection mechanism prevents gdb from running and closes SIP:

    At the moment of restart, hold down the command + R key until the Apple icon and progress bar appear, wait for a while and enter Recovery Mode . Note that it is not after the restart is complete that the login password has not been entered to enter the startup process at this time.
    Close the pop-up page. Select Terminal in the upper toolbar and enter the following commands:

    csurtil enable --without debug
    

    After restarting the computer, run gdb.

PS So far, I have encountered all the problems and corresponding solutions during the installation process. When I first arrived in a foreign country, I began to study professionally. A small problem has afflicted me for almost a week, but I was still very happy when I solved it. I hope that when I encounter such problems in the future, I can calm down and take my time.


  1. https://blog.csdn.net/nixebo/article/details/70196732 ↩︎

  2. https://www.emacswiki.org/emacs/LineNumbers ↩︎

  3. https://blog.csdn.net/github_33873969/article/details/78511733 ↩︎

  4. https://blog.csdn.net/lllkey/article/details/79423596 ↩︎

  5. https://blog.csdn.net/lifujie1554883155/article/details/79661584 ↩︎

  6. https://blog.csdn.net/slvm_lj/article/details/69226927 ↩︎

Published 9 original articles · won 0 · views 866

Guess you like

Origin blog.csdn.net/weixin_43138930/article/details/83044154