장애 상황 테스트를 위해 프로세스를 멈췄다가 실행할 일이 생겼다. 

콘솔 프로그램이라서 예전처럼 드래그하면 멈출 줄 알았는데 윈도우즈11 명령창은 멈추지 않았다.

예전엔 작업관리자에 Suspend 같은게 있었던 것 같은데 윈도우즈 11에서는 없었다.

https://stackoverflow.com/questions/11010165/how-to-suspend-resume-a-process-in-windows

 

How to suspend/resume a process in Windows?

In Unix we can suspend a process execution temporarily and resume it with signals SIGSTOP and SIGCONT. How can I suspend a single-threaded process in Windows without programming ?

stackoverflow.com

검색해보니 아래와 같은 방법들이 있었다.

1. SuspendThread, ResumeThread / NtSuspendProcess / DebugActiveProcess 를 이용하는 프로그램 만들기
2. Invoke-WindowApi 를 통해 DebugActiveProcess 를 호출하는 PowerShell Script 만들기
3. SysInternals 의 Process Explorer 이용하기

Process Explorer 를 이용하는 방식이 제일 간편했다. 프로세스 목록에서 대상 프로세스 선택 후 오른쪽 마우스 메뉴에서 Suspend / Resume 을 선택하면 된다.

728x90
// a.cpp

const std::string STR_A = "abcd";

// b.cpp

B g_b;

B::B()
{
	std::cout << "B::B()" << std::endl;
	std::cout << "a : " << STR_A.c_str() << std::endl;
	
	v = STR_A;
}

void B::testFunc()
{
	std::cout << "B::testFunc()" << std::endl;
	std::cout << "v : " << v << std::endl;
}

// main.cpp

int main()
{
	g_b.testFunc();
}

a.cpp : STR_A 라는 글로벌 변수가 있다.
b.cpp : g_b 라는 글로벌 변수가 있는데 STR_A 를 사용한다.
main.cpp : main 에서 g_b 를 사용한다.

$ g++ -c a.cpp b.cpp c.cpp
$ g++ a.o b.o c.o
$ ./a.out
B::B()
a : abcd
B::testFunc()
v : abcd

컴파일하고 링크했을 때 g_b 가 잘 초기화된 걸로 보인다.

$ g++ b.o a.o c.o
$ ./a.out
B::B()
a :

하지만 오브젝트 파일 순서를 바꿔서 링크하면 main 호출 전에 crash 가 발생한다. STR_A 가 초기화 되기 전에 g_b 가 사용하려고 해서 access violation 이 발생한 것 같다.

g++ 은 입력된 object 순서대로 link 된 것 같은데 컴파일러마다 순서가 다를 수도 있으니 주의하자.

참고 : https://isocpp.org/wiki/faq/ctors#static-init-order

 

Standard C++

 

isocpp.org

 

728x90

rebase 대신 reset 을 입력해 commit 된 작업을 날려버릴 수 있다.

$ git reset master
Unstaged changes after reset:
D       c.txt

'branch2 - 1' 이 날라갔다.

$ git reflog
04a157f (HEAD -> branch2, master) HEAD@{0}: reset: moving to master
a155f44 HEAD@{1}: commit: branch2 - 1
...

날라가기 전으로 되돌리기 위해 reflog 로 시점을 확인하자. HEAD@{1} 로 되돌리면 된다.

$ git reset --hard HEAD@{1}
HEAD is now at a155f44 branch2 - 1

reset 명령어를 사용해 HEAD@{1} 로 되돌리면 된다.

https://88240.tistory.com/284

 

[GIT] reset 한거 취소하는 방법

원래는 remote 에 올리지 않은 여러 commit 이 있는 상태에서 한참 개발 중에 잠시 이전 commit 소스로 돌아가서 확인 좀 하려 했다.믈론 check out 으로 이동해도 되지만, 현재까지 작성한 코드랑 계속

88240.tistory.com

https://seosh817.tistory.com/297

 

[Git] git reflog를 이용하여 git reset --hard로 지워진 커밋 복구하기

Git reflog란? git reflog는 로컬 저장소에서 HEAD의 업데이트를 기록을 출력합니다. 업데이트의 내용은 저장소 디렉토리의 .git/logs/refs/heads/. 혹은 .git/logs/HEAD에 기록되며 git reflog는 이 내용을 출력합니

seosh817.tistory.com

 

728x90
int a{0};

switch (a)
{
case __LINE__: // error C2131, error C2051
	a = 1;
    break;
case __LINE__:
	a = 2;
    break;
default:
	break;
}

'__LINE__' 매크로를 case 와 사용하면 아래와 같은 컴파일 오류가 뜬다.

1>  ConsoleApplicationTest.cpp(12,10): error C2131: 식이 상수로 계산되지 않았습니다.
1>  ConsoleApplicationTest.cpp(12,10): message : 비상수 인수 또는 비상수 기호를 참조하여 실패했습니다.
1>  ConsoleApplicationTest.cpp(12,10): message : '__LINE__Var' 사용량 참조
1>  ConsoleApplicationTest.cpp(15,10): error C2131: 식이 상수로 계산되지 않았습니다.
1>  ConsoleApplicationTest.cpp(15,10): message : 비상수 인수 또는 비상수 기호를 참조하여 실패했습니다.
1>  ConsoleApplicationTest.cpp(15,10): message : '__LINE__Var' 사용량 참조
1>  ConsoleApplicationTest.cpp(12,1): error C2051: case 식이 상수가 아닙니다.
1>  ConsoleApplicationTest.cpp(15,1): error C2051: case 식이 상수가 아닙니다.

릴리즈로 빌드할 때는 오류가 발생하지 않는데 디버그로 빌드할 때만 오류가 발생했다.

https://stackoverflow.com/questions/11461915/visual-studio-9-0-error-c2051-case-expression-not-constant

 

Visual Studio 9.0 Error C2051 Case Expression Not Constant

When I try to compile this code, I get a Case Expression Not Constant error. I can't figure out why. while ((*datalen) == 0) crReturn(NULL); //error here st->len = (st->len << 8) ...

stackoverflow.com

 

검색해보니 '디버그 정보 형식'이 '편집하며 계속하기 프로그램 데이터베이스(/ZI)' 를 사용 중이면 __LINE__ 이 숫자값이 아니게 된다고 한다.

위와 같이 'case __LINE__' 같은 식으로 사용하고 싶으면 '디버그 정보 형식'을 다른 값으로 바꿔 사용해야 했다.

728x90

어느 날 부터인가 엣지를 열면 크롬에서 열던 페이지가 열려서 짜증났다.

https://answers.microsoft.com/en-us/microsoftedge/forum/all/edge-opens-up-pages-from-other-browsers/ad26925e-f4a9-4e15-a6c4-0310b428bad8

 

리디렉션 중

 

login.microsoftonline.com

언제 들어간지는 모르겠지만 '실행할 때마다 Google Chrome에서 브라이저 데이터 가져오기' 가 켜져 있어서 발생한 문제였다.

edge://settings/profiles/importBrowsingData/importOnLaunch 로 접근하거나 설정 > 브라우저 데이터 가져오기 > 각 브라우저 시작 시 검색 데이터 가져오기 로 위 페이지에 접근해 위 옵션을 끄면 된다.

728x90

https://llvm.org/devmtg/2017-10/slides/Ueyama-lld.pdf

리눅스에서 gcc 로 빌드하는 시간이 너무 오래 걸리는 것 같아서 검색해봤다.

https://stackoverflow.com/questions/5142753/can-gcc-use-multiple-cores-when-linking

 

Can gcc use multiple cores when linking?

So when compiling tons of source files with GCC one can use -j to use all available cores. But what about the linker? Is there a similar option to speed up linking or does GCC not support multi-thr...

stackoverflow.com

기본 linker 가 bfd 인데 gold 로 바꾸면 빠르다는 글을 봤다.

gold 는 abstract layer 를 제거하고 다시 설계한 linker 인가 보다.

clang 의 lld 가 gold 보다도 더 빠른 것 같다.

lld 는 파일 복사와 문자열 상수 처리를 동시에 처리해서 속도를 줄였다고 한다.

https://github.com/rui314/mold

 

GitHub - rui314/mold: Mold: A Modern Linker 🦠

Mold: A Modern Linker 🦠. Contribute to rui314/mold development by creating an account on GitHub.

github.com

조금 더 빠를 수 있는 mold / sold 도 있다.

참고로 우리 경우에는 gold 는 큰 차이 없었고 lld 는 의미있는 시간 차이를 보여줬다.

728x90
uint16_t cluster_pool::slot_from_key(const std::string &key)
{
    static const std::regex slot_regex("[^{]*\\{([^}]+)\\}.*");
    std::smatch results;
    uint16_t slot = 0;
    if ( std::regex_match(key, results, slot_regex))
    {
        slot = utils::crc16(results[1]);
    }
    else
    {
        slot = utils::crc16(key);
    }
    return slot & 0x3FFF;
}

https://github.com/luca3m/redis3m/blob/master/src/cluster_pool.cpp

 

GitHub - luca3m/redis3m: A C++ Redis client

A C++ Redis client. Contribute to luca3m/redis3m development by creating an account on GitHub.

github.com

 

redis3m 사용중인데 lib 를 새로 빌드했더니 regex 에서 exception 이 발생했다.

https://stackoverflow.com/questions/12530406/is-gcc-4-8-or-earlier-buggy-about-regular-expressions

 

Is gcc 4.8 or earlier buggy about regular expressions?

I am trying to use std::regex in a C++11 piece of code, but it appears that the support is a bit buggy. An example: #include <regex> #include <iostream> int main (int argc, const char *

stackoverflow.com

확인해보니 regex 는 GCC 4.9.0 에 구현되어 릴리즈 되었다고 한다. 미구현인데 컴파일은 가능해서 런타임에 오류가 발생하는 상황이었다. :(

728x90

특정 버전 이전 gcc 로 빌드된 라이브러리에서 문제가 있었다. 빌드된 lib 가 gcc 어떤 버전으로 빌드된 것인지 확인해봤다.

strings -a <binary/library> | grep "GCC: ("

strings 명령어를 사용해서 추출했다.

$ strings -a a.out | grep "GCC: ("
GCC: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.4.0-1ubuntu1~20.04.1' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-Av3uEd/gcc-9-9.4.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)

https://stackoverflow.com/questions/2387040/how-to-retrieve-the-gcc-version-used-to-compile-a-given-elf-executable

 

How to retrieve the GCC version used to compile a given ELF executable?

I'd like to retrieve the GCC version used to compile a given executable. I tried readelf but didn't get the information. Any thoughts?

stackoverflow.com

strip 명령어를 사용해서 문자열을 날려버리면 확인할 수 없다. :(

728x90
$ du -sh *
765M    BoostEchoClient
6.2M    fmt_join
51K     git
157K    malloc_trim
12M     oneTBB-2021.5.0
3.1M    oneTBB-2021.5.0.zip
61M     oneapi-tbb-2021.5.0-win
16M     oneapi-tbb-2021.5.0-win.zip
2.1G    pp
28K     pp_20211108.zip
51M     protobuf-all-3.19.4
9.6M    protobuf-all-3.19.4.zip
2.9M    protoc-3.19.4-win32
1.2M    protoc-3.19.4-win32.zip
3.8M    protoc-3.19.4-win64
1.5M    protoc-3.19.4-win64.zip
24K     tar
53M     test
52M     test2

linux 에서 du 명령어를 통해 디렉토리 사용량을 확인할 수 있다. du -sh * 를 통해 현재 경로 1 depth 사용량을 알 수 있다.

  -s, --summarize       display only a total for each argument
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)

s 옵션은 요약, h 옵션은  K / M / G 단위로 보여달라는 의미다.

https://gun0912.tistory.com/22

 

[Linux]남은 용량 확인하기

디스크 전체 남은용량 확인 - df : 남은용량 확인(기본 명령어) - df -h : 깔끔하게 정리해서 보여줌 - df . : 현재 경로의 디스크용량만 확인 - df -m, -k : megabyte, kilobyte단위로 확인 현재 경로 아래의 사

gun0912.tistory.com

 

728x90
echo %cd%
pause

윈도우즈 배치파일에서 '%cd%' 를 사용하면 현재 디렉토리를 알 수 있다. 이를 이용해 스크립트 실행경로에 이용할 수 있다.

C:\Windows\System32>echo C:\Windows\System32
C:\Windows\System32

C:\Windows\System32>pause

하지만 관리자 권한으로 실행하면 C:\Windows\System32 실행된다.

D:\test\work\test>call cd\test.bat

D:\test\work\test>echo D:\test\work\test
D:\test\work\test

D:\test\work\test>pause

그리고 다른 경로에서 실행할 경우 %cd% 는 그 실행할 디렉토리를 가리키게 된다.

echo %~dp0
pause
D:\test\work\test>call cd\test.bat

D:\test\work\test>echo D:\test\work\test\cd\
D:\test\work\test\cd\

D:\test\work\test>pause
계속하려면 아무 키나 누르십시오 . . .

스크립트 파일의 경로를 알고 싶으면 '%~dp0' 를 사용한다. 경로가 \ 로 끝나는 점만 주의하자.

https://stackoverflow.com/questions/3827567/how-to-get-the-path-of-the-batch-script-in-windows

 

How to get the path of the batch script in Windows?

I know that %0 contains the full path of the batch script, e.g. c:\path\to\my\file\abc.bat I would path to be equal to c:\path\to\my\file How could I achieve that ?

stackoverflow.com

 

728x90

+ Recent posts