Last year after graduation to company, as a newcomer, found a lot of things have no document, various tools and address is word of mouth, and a lot of the time is don’t know what tools you can use, so when you want to put yourself in contact with the record of these things, for others to provide the reference, the equivalent of a roadmap, help the couple to get started as soon as possible.

This article introduces some development processes and related tools of my group. As a beginner’s manual, some of these tools may only be used in our company, but they are also instructive for beginners in other companies.

2015.4.11 update:

  1. Added build tools Bazel, CMake introduction
  2. Added commands related to task management in Linux
  3. Added regular expression debugging url

A brief introduction to the development background of our group: our business is an HTTP service externally, and the development is mainly server-side development. Programming language: mainly C++/Java, with a small amount of perl and shell scripts released. Deployment mode: hit RPM packages through ABS, put them into the company’s internal yum source, and then release them automatically through the pyramid

Familiar with Linux operations

Task management

If you run a command on the command line to copy a large file, the command is time-consuming and monopolizes the terminal. In this case, you can use Ctrl+ Z to suspend the current job, enter the command, and then use bg to run the pending job in the background.

Using the jobs command, you can view the program and job-ID that is currently running in the background. If you want it to run in the foreground, you can run fg [%job-id] to restore it to the foreground

What if you want to kill a task that is currently running in the background? Use the kill % job – id

Development environment setup

Our operating system is Red Hat Enterprise Linux 5, and our machines are all X86 architecture and 64-bit machines. All the code files here are encoded by GBK by default

  1. Login machine configuration group skip, SSH configuration will be automatically broken after a period of time without operation, and each login will need to enter password +token, use SSH ControlMaster, you can solve, see my SSH configuration

    Under Linux, there are many window managers that can run multiple independent sessions in a single window [without opening multiple terminals] for session recovery [even if the network connection is down, the user does not lose control of the command line session that has been opened]. Screen is recommended

    The default Screen configuration is clunky and conflicts with shell shortcuts. Once configured, the screen display is very powerful. You can refer to my Screen configuration for screen shortcut keys corresponding to the above configuration: Ctrl+ J, C To create a new session Ctrl+ J, D detach

  2. The GNU tool chain

    GNU compilers: GCC * GNU binary tools: includes linker, assembler, and other tools

  3. The code editor

    I started using Vim with very few plug-ins, and then moved to Emacs, mainly Emacs. Eshell and GDB together not only satisfied my daily needs, but also made me feel much more efficient, and emacs environment was relatively easy to install. But on our servers, Vim is standard; Emacs has to install it itself. When I got used to Emacs and switched back to Vim, I forgot all the shortcuts. It was painful!

    Vim beginners information and some practical tips for Vim

    This article explores the causes and solutions of garbled characters in shell and VIM in Linux environment

    Emacs installation and use, now dig a hole here, I will write later

    If you look at the code under Windows, I recommend Source Insight, which is very useful, who knows who uses it.

Code versioning

Currently, the code version management of through train uses SVN common commands:

  • View the changes made to the local code SVN ST-Q

  • SVN ci Filepath / -m “SVN Comments”

  • SVN diff -r r1:r2 SVN diff -r R1 :r1 — Summarize # This command is in summary mode, showing only the file changes, not the specific file content diff

  • Create a branch SVN cp http://destpath/trunk http://destpath/branches/my-branch/ -m “create branche for XXX.” “

  • Merge branch code to main __SVN merge-r 14829:HEAD my/branch http://path/to/trunk__

    The preceding command merges the local SVN path 14829 represented by my/branch to the latest version code into the http://path/to/trunk path. If it is a branch that is normally pulled out, the SVN can automatically calculate the start version number of the branch. When merging code, please pay attention to it. Before submitting the merged code, confirm whether it is OK

  • Check who changed SVN Blame filename at the end of a piece of code

  • SVN up -r rev file Updates the specified file to a specified version

  • SVN Revert file # This command should be used with caution as you cannot find your changes after using it

  • If SVN merger prompt after merger: local add, incoming add upon merge, use the following command to accept the local modification: svn resolve –accept working -R [–recursive]

On a Mac, you are advised to use THE GUI Meld as the SVN merge tool to handle conflicts and reduce the possibility of merge codes

Development [the phase playfully referred to as bug writing]

Before developing, it’s good to know the following:

  • Makefiles are things used to do automated compilation

    Relevant information can refer to Chen Hao wroteWrite the Makefile with meSeries, can search on the net enthusiastic net friend collatesPDF version. After reading the first 4 chapters is enough, the following chapters can be referred to when in doubt.

    You can verify that you understand the Makefile of the entire project by asking the following common questions

    1. How do I modify the Makefile to compile a version with/without GDB debugging information
    2. How do I remove/add compiler optimizations such as the -O2 argument
    3. How to add rules to makefiles after adding header files (usually ending in.h) and source files (usually ending in.cpp). The added file may end up in the static library. A, the dynamic library. So, or it may directly generate the executable

    Instead of writing makefiles directly, cmake(Cross platform make) is used to generate makefiles and then build software as make.

    Advanced Reading: How to debug Makefile variables

  • About static libraries and dynamic libraries

    Things to know

    1. What are static and dynamic libraries
    2. How: How to generate static libraries, dynamic libraries
    3. LibraryArchives-StaticAndDynamic,shared libraries (LibraryArchives-StaticAndDynamic,shared libraries

References:

  1. Novice C compiler, link may encounter two problems

  2. “Self-cultivation of Programmers — Linking, Loading and Libraries”

  3. The book “Deep Understanding of Computer Systems” recommended by zhao is very thick, so you can pick and see the chapters you care about

  • GNU compiler GCC

    You need to know at least a few common option parameters:

    1. Define the name of the output file
    2. Generate GDB debug information
    3. Controls the level of code optimization
    4. Just preprocessing can help debug some of the macro definition/header inclusion issues
    5. Only the compilation process takes place
    6. Only the linking process takes place

    You can use man GCC to get the answer to the above questions, or you can Google by yourself. If Google is blocked, you can use ask

  • GNU debugger GDB program execution result error how to do? What if you can’t pass the single test? What if Core is out online? Don’t worry, GDB is here to help you.

    How do newbies survive in GDB? A small example to get a new user up and running quickly

    Some debugging methods you should know about in GDB

    Some GDB commands that I found [will continue to be updated, please reply] :

    • View the contents of the pointer array __p /x *address@len__ to display len elements starting with address in hexadecimal format
    • Set follow-fork-mode child set follow-fork-mode child

      Services on the Through-train side are basically multi-process models, starting a single daemon parent process and then forking out several child processes to execute the business logic. If the child dies, the parent restarts one of its children.

    Advanced reading:

    Chen Hao with GDB debugging program series, the introduction of a very detailed, comprehensive

Multithreading support

At present, the multithreading mechanism used in the throughtrain is POSIX Theads

For POSIX Theads, know:

  1. What is a pthread
  2. How: How to use pThreads
    • How do I compile multithreaded programs
    • How do I create/terminate a thread
    • How to wait for child threads to return (join/detach)
    • How to use Mutex to synchronize, lock and avoid race conditions between multiple threads?
  3. Why: Use pThreads and not others

All of these questions can be answered in this pTHEAD tutorial from Lawrence Livermore National Laboratory

Find/replace strings/find files/text processing

  • What if you want to find the definition of a macro/function?

    grep -r –include=*.{cpp,h} NGX_HTTP_VAR_INDEXED src/

    SRC recursively looks for NGX_HTTP_VAR_INDEXED in.cpp or.h files

  • What if you want to find a file whose name you vaguely remember?

    __find ./ -iname “*util.h”__

    This command is used to find files in the current directory based on the case-insensitive file name, which is the regular expression *util.h

    For regular expressions, I only read this article by DeerChao: a 30-minute Introduction to Regular Expressions

    Another web application that works especially well is Regexr, which helps you debug regular expressions

  • Text processing

    The streaming editor sed

    For example, to replace a string: sed -i ‘s/ oldValue /newvalue/g

    Text processing language AWK

    For sed, see the AWK tutorial on the cool shell

Advanced reading:

  1. Linux Tips you should know
  2. 28 Unix/Linux command-line artifacts

About Unit Test

Single testing is important because it gives you confidence and confidence in your code, and helps you find problems and fix them earlier. The later a problem is discovered at each stage of development, the more costly it becomes to fix it. Google’s gtest framework is used for all C++ single tests. Even if you don’t know gtest framework before, you can write single tests by looking at other people’s code, but it is better to have a look at the official documents of gtest, to have a comprehensive understanding of gtest, and to expand your thinking.

What if as you write code, your code becomes more and more complex, harder to read, and confusing? You can refer to this great book: < Complete Code 2nd Edition >>

Compile, build

  1. Preparation before compilation

    Need to compile the dependency environment to fix, basically is to install a good compile dependency package can be. You can find the spec file in the RPM directory, and then use the t-abs command [for local debugging of spec files and automatic deployment of the build environment] to help you install the compile-dependent packages, which are specified in the BuildRequire section of the spec file

    For more information about RPM and spec files, read this:How to create an RPM package

  2. compile

    To compile the build project, find the corresponding Makefile and execute the make command

    Because of the flexibility of Make itself, and the low readability of Makefiles, which are based on files and lack of abstraction level, Google developed a distributed build system called Bazel, which can free programmers from the syntax and file-level build of Make.

    Bazel is the most popular Bazel in the world

At present, we are still using RPM for package management

  • RPM commands are as follows:
    1. RPM -qf file-name To check which RPM package a file belongs to
    2. RPM -qi package-name Displays information about the RPM package, such as the package time and SVN address
    3. RPM -ql package-name to check what files are in the RPM package
    4. RPM -qv package-name: RPM -qv package-name: RPM -qv package-name: RPM -qv package-name: RPM -qv package-name: RPM -qv package-name: RPM -qv package-name

Code review

UI interface: reviewBoard, RBT command is used when submitting: RBT post R1 R2 to submit diff between r1 and R2 as codereview can get a Reviewboard address, and then need to fill this address codereView personnel and related description, etc

Continuous integration of CISE

CISE provides users with automated environment deployment and testing services that each company uses differently

The installation package

For built RPM packages, use yum to install them.

Here you can view the existing versions of each package in Taobao yum source. You can see the ABS address of the corresponding package from inside

Use the following command to install:

sudo yum install -b test t-imatch-kgb-updated

The -b parameter specifies whether the current installation package t-imatch-Gb-updated in test or current must be updated to current