gramatická analýza: present gerund, masculine sg form of drbat se, modifying dodával
parafráze: dodával, a přitom se drbal tužkou ve vlasech

gramatická analýza: Dodával drbaje se tužkou ve vlasech.

The main conjugated verb is dodával. The subject for the verb is therefore masc. sg. drbaje se is a present verbal adverb, masculine sg form of drbat se. The verbal adverb adds information to the main verb, what the person was making an utterance.

Try paraphrasing the sentence another independent clause: "he added and at the same time scratched his hair with a pencil."