Blog overview

Latest entries:

2021-08-15: Data corruption on Amiga 600/1200 IDE controller

I have used an IDE drive for a long time in my Amiga 600, starting with a 250MB spinning disk in the 90s and later on using a compact-flash to IDE converter. Over all these years I had no noticeable problems with that setup. But recently, while testing data transfer between my PC and the Amiga, I noticed some weird file corruption happening sometimes even though the different transfer software I used have some sort of checksumming.

1. What was happening?

I finally was able to reproduce it by simple copying a file of half a megabyte or so from the IDE device to ram. I tried different tools and while my main tool of choice, Directory Opus, worked fine, the command line tool "copy" created a corrupted file. I tested some other tools like cp from a GNU installation with mixed results. Some worked fine, others created corrupted files too.

Eventually I wrote a simplified file copy program with configurable buffer size and I was finally able to find out that using buffers larger than 128k make the problem appear. The AmigaOS tool "copy" also has a option "BUF" to choose the buffer size which is a multiple of 512 byte blocks. Up to a value of 256, the copy was correct, larger values created corrupted files.

I suspected either a hardware problem with my machine or the compact flash card, or some transfer size limitation of the IDE controller. After some web research, I found that the IDE controller indeed apparently only supports transfers of 255 512 bytes blocks, or there is some compatibility problems with newer ATA versions:

Either way, the maximum transfer size must be limited to avoid data corruption.

The whole time my disk was configured with a default value of the maximum transfer size of 16 MByte. I then used the HDToolBox program to modify the value to 0x1fe00 (255*512) and finally all copy operations worked fine again.

You can make the adjustment on the live partition, you don't need to reformat anything. To apply the changes, open the HDToolBox program, select your drive and choose "Partition Drive". For each partition on that drive, show the "Advanced Options" and click on "Change File System for Partition". In that dialog, you can enter a new value for "MaxTransfer". Choose "Ok" and repeat for any other partition. When done, click on "Ok" partition window and in the main window click on "Save Changes to Drive". I'm not sure if the parameters take immediate effect, so probably just reboot to be safe.

2. Conclusion

I can't believe the IDE compact flash was misconfigured all the time and I never noticed any data corruption, probably due to the fact that most the file operations I was doing was done by Directory Opus, which apparently uses a smaller buffer size when copying files.

Considering that there is no hint about the correct value while preparing an IDE drive (spinning or flash based), I think it might be helpful to share this information (even though probably not many need that information anyway nowadays).

tags: amiga7

2021-07-12: Debug symbol download in gdb

Since I had OpenSuse tumbleweed running on my laptop, I noticed an issue with gdb downloading quite a lot of debugging symbols. I did not know why it happens, nor where it loads the symbols from, nor how to stop it from doing so.

Due to the nature of a rolling linux distribution, base packages get updated quite often. So the debug symbols for many base libraries need to be downloaded again and again for every update which is really annoying.

I can see that there are use cases where it helps to have access to debug symbols from build servers, but I don't know why it is enabled by default. It is very hard for users to see what is happening, why gdb accesses some server the user did not configured, storing data on some unknown location, and how to stop.

I personally don't need that functionality at all and it gets in my way more often than not. When debugging a locally built binary, I do have the symbols in place, and for all third-party libraries I don't need the symbols most of the time. On slow network connections, it can take a long time (several minutes) to get all symbols, and the user does not even get at least some basic progress feedback. Sometimes it is possible to abort the download with Ctrl-C but in my experience it does not work reliable and also only for a single library, so even it works, you have to press it quite often.

I expect to have debugging symbols as part of the devel package, or some separate debug packages. In OpenSuse, those packages are named *debuginfo*.

This feature can also be a security issue, especially if the user does not know why it download stuff and from which server.

So here is what is happening and how to avoid/configure it at least.

1. What is happening?

Since version 10.1 gdb supports Debuginfod, a server infrastructure for getting debug symbols for a given build ID.

OpenSuse installs a package named libdebuginfod which sets up the stuff so GDB contacts https://debuginfod.opensuse.org/ for symbols. The environment variable DEBUGINFOD_URLS describes the server to use. It is defined in the file /etc/profile.d/debuginfod.*

2. How to disable it

There are two ways to disabled the use of online servers.

You can undefine the environment DEBUGINFOD_URLS to temporarily disable it.

To permanently disable it, uninstall the package libdebuginfod1. It will install a dummy package instead.

3. Final thoughts

This feature can be quite useful in certain environments, but in my opinion, it should not be enabled by default. There are quite some downsides:
  • downloads a lot of data
  • unaware user can't see where the data is coming from
  • no progress indication, can take a few seconds or several minutes
  • no hint how to configure/disable it
  • it is completely unclear from gdb changelog and debuginfod web page, if the data downloaded is signed with a well-defined gpg key to avoid security issues with handling untrusted data
tags: gdb1

2021-03-16: Code completion for emacs with LSP

1. Overview

There are a lot of packages for code development in emacs for a varity of languages, like cedet, company and others. The feature set starts from some keyword lookup for references, project handling, and code completion.

The language server protocol (LSP) is powerful,generic way to integrate IDE features into editors. For emacs, there is the lsp-mode which works great. There is excellent documentation at the homepage, but I wanted to write down some condensed steps to install it.

2. Installation

The simplest way to install is to use the emacs package manager and install the package "lsp-mode".

You need a LSP backend. For C there are two implementations, clangd is one of it so you might want to install that. It will be used automatically if it is available.

For a quick test, you can open a C file and execute "M-x lsp". I experienced a problem with an undefined symbol "-compose" which came from an old version of "dash" so you might want to update this package as well.

When opening a C file, emacs usually asks you to import the file as a project, you can press "i" to just import the current file or use "I" to manually set the project root directory which is often so better option. The project information are stored in the file

~/.emacs.d/.lsp-session-v1

3. Helping clangd to know about the project

clangd need to know how to compile the project and where to find include files etc. For this, a file named "compile_commands.json" must be created.

There are different ways to create such a file for different build environments. You can create the manually if you want to. For cmake you can use the option "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON". For make based project you can use the tool "bear" to create the file tool. Run "bear make" to create this file.

When everything is set up, you should be able to open any C/C++ file and start the lsp integration with "M-x lsp" (when applying the config in the next section, it will be done automatically). Then tab completion should just work if you have company active. You can also try to press M-. to jump to definition of a symbol.

4. Configuration

I use the following config to automatically enable lsp:
(add-hook 'c-mode-hook 'lsp-deferred)
(add-hook 'c++-mode-hook 'lsp-deferred)
(setq gc-cons-threshold (* 100 1024 1024)
      read-process-output-max (* 1024 1024)
      treemacs-space-between-root-nodes nil
      company-idle-delay 0.0
      company-minimum-prefix-length 1
      lsp-idle-delay 0.1)
(with-eval-after-load 'lsp-mode
 (add-hook 'lsp-mode-hook #'lsp-enable-which-key-integration))

5. Remaining issues

I experienced the following small issues:
  • I got a message
       Error running timer lsp--on-idle: (wrong-type-argument listp
       
    and it looks like it comes from the breadcrumb integration. You can disable the breadcrumb by running "M-x lsp-headerline-breadcrumb-mode" or disable it completely by using the configuration
       (setq lsp-headerline-breadcrumb-enable nil)
       
  • tab completion collides with yas-snipplet sometimes. I don't have a solution right now, you have to cancel the completion C-g and press tab again to get the yas-snipplet completion.
  • lsp sometimes asks for system includes to be part of the project, I don't know an other workaround than blacklisting them (the dialog allows to do that).

6. Final notes

This is just a very short version of how to install this mode but there is a nice tutorial at the "lsp-mode" homepage with a lot of more information.
tags: emacs2

All blog entries: all